Reputation: 91
My XML doc looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<XCER xmlns="http://www.x.y.z/base" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.x.y.z/base APSchema.xsd" mp_id="56977" ma_id="398" sub_id="54977">
<final_result OD="DGS=1.7:ADB=2" creator="Px" version="1.1" xsi:type="XCT">
<code>3040280100331</code>
<code_cnf>1.0000</code_cnf>
<code_attr>seq</code_attr>
<status_attr>fdos</status_attr>
<text>xxx</text>
<standardized_text>xxxx</standardized_text>
<region>
<type>address</type>
<symbology>machine</symbology>
</region>
<recognized_elements>
<type>reg</type>
<nominal>
<type>reg</type>
<code>Dx</code>
<code_cnf>0.0635</code_cnf>
<location page="3">
<face>rear</face>
<polygon>
<dot x="720" y="709" />
<dot x="744" y="708" />
<dot x="744" y="591" />
<dot x="720" y="592" />
</polygon>
</location>
</nominal>
<reference>
<type>reg</type>
<code>Dx</code>
<match_cnf>1.0000</match_cnf>
<attribute>full_match</attribute>
</reference>
</recognized_elements>
<recognized_elements>
<type>cty</type>
<reference>
<type>cty</type>
<code>Dx 9</code>
<attribute>derived</attribute>
</reference>
</recognized_elements>
<standardized_elements>
<type>reg</type>
<code>Dx</code>
</standardized_elements>
<standardized_elements>
<type>cty</type>
<code>Dx 9</code>
<attribute>err</attribute>
</standardized_elements>
</final_result>
</XCER>
And I want to do a couple of things with it and I cant figure out how using XPath and I can find the specific case I need in the examples I find on line. My problem is I want to find 'Dxf' which is in Recognized_elements:reference:code but only when the is 'reg' and the is full_match>
The expression I have which does not work is the following:
doc.SelectSingleNode("/x:XCER[0]/x:final_result[@creator = 'Px']/x:recognized_elements/x:reference[type='reg' and attribute='full_match]/x:code", nsmgr).InnerText
the error I always get is as follows: 'Object reference not set to an instance of an object'
Upvotes: 1
Views: 532
Reputation: 43743
I think what you need is this:
doc.SelectSingleNode("/x:XCER/x:final_result[@x:creator = 'Px']/x:recognized_elements[x:type='reg' and x:reference/x:attribute='full_match']/x:reference/x:code", nsmgr).InnerText
You were missing the namespace in a few places and you forgot to put the full path to a couple of the child elements. I'm not sure if you intended to read the reference/code
element or the nominal/code
element.
Upvotes: 1