J
Jason Zhou
Hi,
I am receiving an XML document from other system, and I am using xPath to
search one of the node in the document. For example, the xml document like
this:
<Company>
<Employees>
<Employee ID="1">
<FirstName>Klaus</FirstName>
<LastName>Salchner</LastName>
<PhoneNumber>410-727-5112</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<WebAddress>http://www.enterprise-minds.com</WebAddress>
<JobTitle>Sr. Enterprise Architect</JobTitle>
</Employee>
<Employee ID="2">
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
<PhoneNumber>604-111-1111</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<JobTitle>Sr. Developer</JobTitle>
</Employee>
</Employees>
</Company>
I can use following command to search the node:
XmlNode oNode1 =
oXML.SelectSingleNode("/descendant::JobTitle[ancestor::Employee/@ID=2]");
Where oXML is an XML document object that loaded above xml.
For some reason, the xml I received recently changed a little bit, an extra
xmlns attribute added to both Company and Employees Nodes, and my search
command does not work any more, can anybody give a solution? Thanks in
advance!
p.s. The new XML looks like this:
<Company xmlns="http://schemas.abc.com">
<Employees xmlns="http://schemas.def.com">
<Employee ID="1">
<FirstName>Klaus</FirstName>
<LastName>Salchner</LastName>
<PhoneNumber>410-727-5112</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<WebAddress>http://www.enterprise-minds.com</WebAddress>
<JobTitle>Sr. Enterprise Architect</JobTitle>
</Employee>
<Employee ID="2">
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
<PhoneNumber>604-111-1111</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<JobTitle>Sr. Developer</JobTitle>
</Employee>
</Employees>
</Company>
I am receiving an XML document from other system, and I am using xPath to
search one of the node in the document. For example, the xml document like
this:
<Company>
<Employees>
<Employee ID="1">
<FirstName>Klaus</FirstName>
<LastName>Salchner</LastName>
<PhoneNumber>410-727-5112</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<WebAddress>http://www.enterprise-minds.com</WebAddress>
<JobTitle>Sr. Enterprise Architect</JobTitle>
</Employee>
<Employee ID="2">
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
<PhoneNumber>604-111-1111</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<JobTitle>Sr. Developer</JobTitle>
</Employee>
</Employees>
</Company>
I can use following command to search the node:
XmlNode oNode1 =
oXML.SelectSingleNode("/descendant::JobTitle[ancestor::Employee/@ID=2]");
Where oXML is an XML document object that loaded above xml.
For some reason, the xml I received recently changed a little bit, an extra
xmlns attribute added to both Company and Employees Nodes, and my search
command does not work any more, can anybody give a solution? Thanks in
advance!
p.s. The new XML looks like this:
<Company xmlns="http://schemas.abc.com">
<Employees xmlns="http://schemas.def.com">
<Employee ID="1">
<FirstName>Klaus</FirstName>
<LastName>Salchner</LastName>
<PhoneNumber>410-727-5112</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<WebAddress>http://www.enterprise-minds.com</WebAddress>
<JobTitle>Sr. Enterprise Architect</JobTitle>
</Employee>
<Employee ID="2">
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
<PhoneNumber>604-111-1111</PhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
<JobTitle>Sr. Developer</JobTitle>
</Employee>
</Employees>
</Company>