xml - Section name with multiple words in TNativeXML -
i'm trying make xml file using nativexml v4.09 , used structure :
<?xml version="1.0" encoding="utf-8"?> <root> <word1 word2>this value</word1 word2> </root>
i write simple code :
procedure tform1.buttonwriteclick(sender: tobject); var aaa: tnativexml; vsectionname : string; begin vsectionname := 'word1 word2';//name of section 2 words sparated space aaa:= tnativexml.create(self); aaa.createname('root'); aaa.root.nodenew(vsectionname); aaa.root.nodebyname('word1 word2').value:='this value'; aaa.xmlformat := xfreadable; aaa.savetofile('test.xml'); end;
and read node of section write code :
procedure tform1.buttonreadclick(sender: tobject); var aaa : tnativexml; vsectionname : string; vnode : txmlnode; begin vsectionname := 'word1 word2';//name of section 2 words sparated space try aaa := tnativexml.create(self); aaa.loadfromfile('test.xml'); vnode := aaa.root.nodebyname(vsectionname); if vnode=nil showmessage('section not found') else showmessage('section found'); freeandnil(aaa); end; end;
i can create xml file "test.xml" structure above want to. when want read node section 2 words name (like "word1 word2" name) got message "section not found" because vnode nil nodebyname function.
then tracking error add code in nativexml.txmlnode.nodebyname function this:
function txmlnode.nodebyname(const aname: utf8string): txmlnode; var i: integer; vf : boolean; begin result := nil; := 0 getnodecount - 1 begin vf := (utf8comparetext(getnodes(i).name, aname) = 0); if vf application.messagebox(pwidechar('txmlnode.nodebyname-> found aname='+aname+'|getnodes('+inttostr(i)+').name='+getnodes(i).name+'|getnodes('+inttostr(i)+').nameunicode='+getnodes(i).nameunicode),'txmlnode.nodebyname',0) else application.messagebox(pwidechar('txmlnode.nodebyname-> not found aname='+aname+'|getnodes('+inttostr(i)+').name='+getnodes(i).name+'|getnodes('+inttostr(i)+').nameunicode='+getnodes(i).nameunicode),'txmlnode.nodebyname',0); //if (utf8comparetext(getnodes(i).name, aname) = 0) if vf begin result := getnodes(i); exit; end; end; end;
and messagebox :
i see section name change 2 words ("word1 word2" name) single word ("word1" name).
is bug in section name multiple words name space(s) or section's name must single word without space(s) ? if section's name must single word or more , without space(s), why can create xml section's name 2 or more words space(s) can not section node when read nodebyname ?
your document not valid xml. tag names must not contain space characters.
xml specification: xml start-tags, end-tags, , empty-element tags
Comments
Post a Comment