C# Selecting XML Elements With XPathSelectElements() -
i have xml, there multiple elements of type 'vdsk', want them all. have 1 in here brevity.
<?xml version="1.0" encoding="utf-8" ?> <diskstatscoll xmlns="http://ibm.com/storage/management/performance/api/2005/08/vdiskstats" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://ibm.com/storage/management/performance/api/2005 /08/vdiskstats schema/svcperfstatsv.xsd" scope="node" id="node1" cluster="v7000nd01" node_id="0x0000000000000001" cluster_id="0x00000200a0421666" sizeunits="512b" timeunits="msec" contains="virtualdiskstats" timestamp="2013-04-30 07:04:13" timezone="gmt-6:00"> <vdsk idx="0" ctr="137111307" ctrs="3553815134" ctw="580314768" ctws="12467258075" ctp="107973069" ctps="6910276416" ctrh="91819453" ctrhs="2398189867" ctrhp="67411787"/> <vdsk idx="1" ctr="137111307" ctrs="3553815134" ctw="580314768" ctws="12467258075" ctp="107973069" ctps="6910276416" ctrh="91819453" ctrhs="2398189867" ctrhp="67411787"/> </diskstatscoll>
i can attributes of root element. can't seem of child elements of root.
code works, messy , kludge
list<xelement> allels = ioxdoc.elements().tolist(); list<xelement> allelselements = allels[0].elements().tolist(); var vdisks = vdisk in allelselements. where(a => a.name.tostring().contains("vdsk")) select vdisk;
i trying work xpathselectelements(), have tried these based on examples , examples found here list empty
list<xelement> allels = ioxdoc.root.xpathselectelements("vdsk").tolist(); allels = ioxdoc.xpathselectelements("xml/root/vdsk").tolist(); allels = ioxdoc.xpathselectelements("/root/vdsk").tolist();
why don't this:
var allels = ioxdoc.root.descendants().tolist();
the above line correctly reports 2 <vdsk>
s.
Comments
Post a Comment