i new in delphi, , here thing want do. have xml file formated this,
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <data xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <row> <designation>1234102</designation> <inner>5.412</inner> <outer>3.588</outer> <spin>4.732</spin> <cage>0.399</cage> </row> <row> <designation>1342153</designation> <inner>5.916</inner> <outer>4.084</outer> <spin>5.277</spin> <cage>0.408</cage> </row> ........ </data>
and want query delphi. example: want data of 1342153. best , easiest solution?
thank in advance example , explanation.
i'm going make presumption once find designation
, you're going want read other entries (inner
, outer
, spin
, , cage
) go designation.
xpath
perfect solution problem. example uses new form tmemo
, tbutton
dropped on it, , adding handler button1.onclick
event:
uses msxml, comobj, activex; const xmltext = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>' + '<data>' + '<row>' + '<designation>1234102</designation>' + '<inner>5.412</inner>' + '<outer>3.588</outer>' + '<spin>4.732</spin>' + '<cage>0.399</cage>' + '</row>' + '<row>' + '<designation>1342153</designation>' + '<inner>5.916</inner>' + '<outer>4.084</outer>' + '<spin>5.277</spin>' + '<cage>0.408</cage>' + '</row>' + '</data>'; procedure tform1.button1click(sender: tobject); var xmldoc: ixmldomdocument; node, sibnode: ixmldomnode; begin memo1.clear; xmldoc := codomdocument.create; xmldoc.loadxml(xmltext); // select node designation want. node := xmldoc.selectsinglenode('//designation[text()="1342153"]'); if assigned(node) begin memo1.lines.add('found it.'); memo1.lines.add(node.nodename + ' = ' + node.firstchild.nodevalue); // read nodes @ same level designation sibnode := node.nextsibling; while sibnode <> nil begin memo1.lines.add(sibnode.nodename + ' = ' + sibnode.firstchild.nodevalue); sib := sib.nextsibling; end; end; end;
if want grab of <row>
elements, , loop through information contain, can use (add second button test app above, , use button2.onclick
handler):
procedure tform1.button2click(sender: tobject); var xmldoc: ixmldomdocument; nodelist: ixmldomnodelist; node, sibnode: ixmldomnode; i: integer; begin memo1.clear; xmldoc := codomdocument.create; xmldoc.loadxml(xmltext); nodelist := xmldoc.selectnodes('/data/row'); if assigned(nodelist) begin := 0 nodelist.length - 1 begin node := nodelist.item[i]; sibnode := node.firstchild; while assigned(sibnode) begin memo1.lines.add(sibnode.nodename + ' = ' + sibnode.firstchild.nodevalue); sibnode := sibnode.nextsibling; end; end; // add blank line between groupings readability memo1.lines.add(''); end; end;
Comments
Post a Comment