Unable to parse value from a XML text using XML Binding in Delphi -


i unable extract value following xml file.

<?xml version="1.0" encoding="utf-8"?> <env:envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">    <env:header/>    <env:body env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">       <m:getlistofalllatestvariantsresponse xmlns:m="http://www.posti-care_suite.posti.nokia.com/posti_caresuite_interface.wsdl">          <result soapenc:arraytype="n1:variant5[1]" xmlns:n1="http://posti.nokia.com/server/caresuite/webservice/types">             <variant xsi:type="n1:variant5">                <variantid xsi:type="xsd:long">7115932272</variantid>                <name xsi:type="xsd:string">n8-00 rm-596 country variant united kingdom gb belle v6 dark gre</name>                <productcode xsi:type="xsd:string">059c5q8</productcode>                <mandatoryfilessize xsi:type="xsd:long">319898701</mandatoryfilessize>                <optionalfilessize xsi:type="xsd:long">1045013246</optionalfilessize>                <files soapenc:arraytype="n1:file4[19]">                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_111.040.1511_007.vpl</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">5316</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932073/6425438c_rm596_059c5q8_111.040.1511_007.vpl</downloadurl>                      <checksum xsi:type="xsd:string">1680163724</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_111.040.1511_007.dcp</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">31743</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933784/18333a08_rm596_059c5q8_111.040.1511_007.dcp</downloadurl>                      <checksum xsi:type="xsd:string">406010376</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_111.040.1511_79u_prd.core.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">131593310</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1207/3115/7087503025/rm-596_111.040.1511_79u_prd.core.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">1419340992</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_111.040.1511_01.01_euro_1_79u_prd.rofs2.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">59185951</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1207/3115/7087503335/rm-596_111.040.1511_01.01_euro_1_79u_prd.rofs2.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">956264830</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_111.040.1511_377.01_default_79u.2012.20_prd.rofs3.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">46565</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932076/2c5ce665_rm-596_111.040.1511_377.01_default_79u.2012.20_prd.rofs3.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">744285797</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_111.040.1511_377.01_default_79u.2012.20.uda.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">124438076</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933788/4f8b5cf8_rm-596_111.040.1511_377.01_default_79u.2012.20.uda.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">1334533368</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_ape_only_eno_11w36_v0.162.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">4593644</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1112/1506/6514839560/rm596_ape_only_eno_11w36_v0.162.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">285947104</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_m001.56.emmc.fpsx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">1044986030</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1208/2113/7087773772/8e08b787_rm-596_m001.56.emmc.fpsx</downloadurl>                      <checksum xsi:type="xsd:string">2382935943</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_data_block</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">4112</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2010/6/--fid--a0a22xpgxoefj/--lid--fire1277360142761/rm-596_data_block</downloadurl>                      <checksum xsi:type="xsd:string">166635140</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">ive3_otp_template_production.bin</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">40</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2010/3/--fid--a0a22umcderpy/--lid--fire1269607336867/ive3_otp_template_production.bin</downloadurl>                      <checksum xsi:type="xsd:string">3604450678</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">093490v1.pcx</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">8365</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2010/8/--fid--a0a22uukbnmgx/--lid--fire1281620803410/093490v1.pcx</downloadurl>                      <checksum xsi:type="xsd:string">919543664</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">040-093490_p4067_006.xml</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">2610</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2010/9/--fid--a0a22ggqdqjhv/--lid--fire1285052118474/24d0d5b4_040-093490_p4067_006.xml</downloadurl>                      <checksum xsi:type="xsd:string">617665972</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_size_ccc_v2.0.bin</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">472</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2011/8/--fid--a0a22yxswdmno/--lid--fire1312914775006/e938259f_rm596_059c5q8_size_ccc_v2.0.bin</downloadurl>                      <checksum xsi:type="xsd:string">3912770975</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_size_hwc_v2.0.bin</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">212</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2011/8/--fid--a0a22gthojdfh/--lid--fire1312914776256/a65eb470_rm596_059c5q8_size_hwc_v2.0.bin</downloadurl>                      <checksum xsi:type="xsd:string">2791224432</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">simlock_3gstandard_bb5_crca59a.bin</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">964</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1111/2911/6514812504/simlock_3gstandard_bb5_crca59a.bin</downloadurl>                      <checksum xsi:type="xsd:string">1270261311</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm-596_m001.56.emmc.cardverref.xml</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">386</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1208/2113/7087773773/cb9fed13_rm-596_m001.56.emmc.cardverref.xml</downloadurl>                      <checksum xsi:type="xsd:string">3416255763</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">mc_f_nocard.mcard.cardverref.xml</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">131</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/fire/2011/8/--fid--a0a22alnmvcgg/--lid--fire1314695176834/39195667_mc_f_nocard.mcard.cardverref.xml</downloadurl>                      <checksum xsi:type="xsd:string">957961831</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_007.spr</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">9924</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933803/a4cb1ed5_rm596_059c5q8_007.spr</downloadurl>                      <checksum xsi:type="xsd:string">2764775125</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                   <file xsi:type="n1:file4">                      <filename xsi:type="xsd:string">rm596_059c5q8_111.040.1511_007_signature.bin</filename>                      <relativepath xsi:type="xsd:string">products/rm-596</relativepath>                      <filesize xsi:type="xsd:long">4096</filesize>                      <downloadurl xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932081/590998c6_rm596_059c5q8_111.040.1511_007_signature.bin</downloadurl>                      <checksum xsi:type="xsd:string">1493801158</checksum>                      <checksumtype xsi:type="xsd:int">1</checksumtype>                   </file>                </files>                <variantversion xsi:type="n1:variantversion">                   <swversion xsi:type="xsd:string">111.040.1511</swversion>                   <certificateid xsi:type="xsd:long">0</certificateid>                   <versions soapenc:arraytype="n1:version[0]"/>                </variantversion>             </variant>          </result>       </m:getlistofalllatestvariantsresponse>    </env:body> </env:envelope> 

i extract values variantid, productcode, name child nodes node "variant".

all did using xml binding wizard wrapper unit , threw xmldocument component in form.

my code far parse 'productcode':

procedure tform1.parsexml(const axmltext: string); var   envelopetype: ixmlenvelopetype;   productcode: string; begin   xmldocument1.xml.text := axmltext;   envelopetype := getenvelope(xmldocument1);    productcode := envelopetype.body.getlistofalllatestvariantsresponse.result.variant.productcode.text;   memo2.text := 'product code: ' + productcode; end; 

the problem is, everytime empty string value required node values.

due poor implementation of xml namespaces in delphi's txmlnodelist, code produced xml binding wizard can not work correctly. because root element carries namespace, code assumes have same namespace on childnodes. has side effect xml code can't find correct node when namespace changes case m:getlistofalllatestvariantsresponse. fail understand why has been implemented can have multiple namespaces on childnodes.

you can fix following these steps:

1) copy files xml.xmldoc.pas , xml.xmldom.pas source directory project directory , include them in project

2) modify local xml.xmldoc.pas file

change function function txmlnodelist.findnode(nodename: domstring): ixmlnode;

function txmlnodelist.findnode(nodename: domstring): ixmlnode; begin   result := findnode(nodename, defaultnamespaceuri);   // --> add these lines below   // node not found default namespace, fallback blank namespace   if not assigned(result)    result := findnode(nodename, ''); end; 

3) modify local xml.xmldom.pas file

change function nodematches this:

function nodematches(const node: idomnode; const tagname, namespaceuri: domstring): boolean; begin  result := ((namespaceuri = '') or (samenamespace(node, namespaceuri)) or (node.namespaceuri= '')) ,            ((node.nodename = tagname) or (node.localname = tagname)); end; 

4) modify unit generated xml binding wizard

we must reflect fact getlistofalllatestvariantsresponse node uses namespace:

procedure txmlbodytype.afterconstruction; begin   registerchildnode('getlistofalllatestvariantsresponse', txmlgetlistofalllatestvariantsresponsetype, 'http://www.posti-care_suite.posti.nokia.com/posti_caresuite_interface.wsdl');   inherited; end; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -