eladr
asked on
making XPATH with namespace in the root
Hi...
im getting NULL in the value of the xmlnode.
when i delete the namespace is working.
how can i get the value? should i use namespace manager?
i prefer that xpath wont contain the namespaces.
i need to know if there is at least one "status" element with "false" value.
10x
XmlDocument xmldoc = new XmlDocument();
string xml = "<UpdateXIResponse xmlns='http://Global.Schemas.ScmUpdateXIResponse'><interface_seq>int erface_seq _0</interf ace_seq><i nterface_n ame>interf ace_name_0 </interfac e_name><in terface_da tetime>int erface_dat etime_0</i nterface_d atetime><D ata><Seq_n um>Seq_num _0</Seq_nu m><Ifc_Dat e>Ifc_Date _0</Ifc_Da te><Status >False</St atus><Fail ure_code>F ailure_cod e_0</Failu re_code><F ailure_Rea son>Failur e_Reason_0 </Failure_ Reason>";
xml += "</Data><Data><Seq_num>Seq _num_0</Se q_num><Ifc _Date>Ifc_ Date_0</If c_Date><St atus>True< /Status><F ailure_cod e>Failure_ code_0</Fa ilure_code ><Failure_ Reason>Fai lure_Reaso n_0</Failu re_Reason> </Data></U pdateXIRes ponse>";
xmldoc.LoadXml(xml);
XmlNode xNode = xmldoc.SelectSingleNode("/ /UpdateXIR esponse/Da ta[Status= 'False']") ;
im getting NULL in the value of the xmlnode.
when i delete the namespace is working.
how can i get the value? should i use namespace manager?
i prefer that xpath wont contain the namespaces.
i need to know if there is at least one "status" element with "false" value.
10x
XmlDocument xmldoc = new XmlDocument();
string xml = "<UpdateXIResponse xmlns='http://Global.Schemas.ScmUpdateXIResponse'><interface_seq>int
xml += "</Data><Data><Seq_num>Seq
xmldoc.LoadXml(xml);
XmlNode xNode = xmldoc.SelectSingleNode("/
ASKER
how can i use the namespace manager?...
can u send me some simple example?
can u send me some simple example?
ASKER
in the addnamespace method i need 2 supply prefix which i dont have in the document...
the namespace is global.
the namespace is global.
if there isn't a prefix, the prefix is the empty string
ASKER
Not working...
here the code:
here the code:
XmlDocument xmldoc = new XmlDocument();
string xml = "<UpdateXIResponse xmlns='http://CoIns.Global.Schemas.ScmUpdateXIResponse'><interface_seq>interface_seq_0</interface_seq><interface_name>interface_name_0</interface_name><interface_datetime>interface_datetime_0</interface_datetime><Data><Seq_num>Seq_num_0</Seq_num><Ifc_Date>Ifc_Date_0</Ifc_Date><Status>False</Status><Failure_code>Failure_code_0</Failure_code><Failure_Reason>Failure_Reason_0</Failure_Reason>";
xml += "</Data><Data><Seq_num>Seq_num_0</Seq_num><Ifc_Date>Ifc_Date_0</Ifc_Date><Status>True</Status><Failure_code>Failure_code_0</Failure_code><Failure_Reason>Failure_Reason_0</Failure_Reason></Data></UpdateXIResponse>";
xmldoc.LoadXml(xml);
XmlNamespaceManager xmlnsm = new XmlNamespaceManager(xmldoc.NameTable);
xmlnsm.AddNamespace(string.Empty,"http://CoIns.Global.Schemas.ScmUpdateXIResponse");
int linesCount = xmldoc.SelectNodes("//UpdateXIResponse/Data", xmlnsm).Count;
XmlNode xNode = xmldoc.SelectSingleNode("//UpdateXIResponse/Data[Status='False']",xmlnsm);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
welcome
you have three optons
- change the source XML and remove the namespace
- use a namespace manager
- make your XPath namespace independent:
//*[local-name() = 'UpdateXIResponse']/*[loca
+ the namespace independent XPath is slower
+ I don't like changing a source XML
+ namespace manager is the cleanest solution
cheers
Geert