I'm trying to navigate inside an XML file that has a very simple namespace,
But when I'm using the name space a get nothing (Count == 0) when I do
SelectNodes() or SelectSingleNod e() (null).
When I remove the namespace from the XML file and from the code --> the
Select is successful but I do need to leave the namespace in the XML file.
Here is the XML file I'm using:
<?xml version="1.0" standalone="yes "?>
<MyDB xmlns="DataBase .xsd">
<Subjects>
<Subject>
<ID>Cylinder</ID>
<Defects>
<Defect>
<ID>100</ID>
<Sevirity>10</Sevirity>
</Defect>
<Defect>
<ID>101</ID>
<Sevirity>20</Sevirity>
</Defect>
<Defect>
<ID>102</ID>
<Sevirity>30</Sevirity>
</Defect>
</Defects>
</Subject>
</Subjects>
</MyDB>
And the code using DOM:
XmlDocument doc = new XmlDocument();
doc.Load("EvsDB Output.xml");
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("ns", "DataBase.xsd") ;
// or // nsmgr.AddNamesp ace("", "DataBase.xsd") ;
XmlNode node = doc.SelectSingl eNode("EvsDB/Subjects", nsmgr); // return null
XmlNodeList listSubjects = doc.SelectNodes ("/EvsDB/Subjects", nsmgr); //
return listSubjects.Co unt == 0
XmlNodeList listSubject = doc.SelectNodes ("/EvsDB/Subjects/Subject", nsmgr);
// return listSubject.Cou nt == 0
XmlNodeList listDefect =
doc.SelectNodes ("/EvsDB/Subjects/Subject/Defects/Defect", nsmgr); // return
listDefect.Coun t == 0
Can anybody tell hove to make it work?
--------
Thanks
Sharon
But when I'm using the name space a get nothing (Count == 0) when I do
SelectNodes() or SelectSingleNod e() (null).
When I remove the namespace from the XML file and from the code --> the
Select is successful but I do need to leave the namespace in the XML file.
Here is the XML file I'm using:
<?xml version="1.0" standalone="yes "?>
<MyDB xmlns="DataBase .xsd">
<Subjects>
<Subject>
<ID>Cylinder</ID>
<Defects>
<Defect>
<ID>100</ID>
<Sevirity>10</Sevirity>
</Defect>
<Defect>
<ID>101</ID>
<Sevirity>20</Sevirity>
</Defect>
<Defect>
<ID>102</ID>
<Sevirity>30</Sevirity>
</Defect>
</Defects>
</Subject>
</Subjects>
</MyDB>
And the code using DOM:
XmlDocument doc = new XmlDocument();
doc.Load("EvsDB Output.xml");
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("ns", "DataBase.xsd") ;
// or // nsmgr.AddNamesp ace("", "DataBase.xsd") ;
XmlNode node = doc.SelectSingl eNode("EvsDB/Subjects", nsmgr); // return null
XmlNodeList listSubjects = doc.SelectNodes ("/EvsDB/Subjects", nsmgr); //
return listSubjects.Co unt == 0
XmlNodeList listSubject = doc.SelectNodes ("/EvsDB/Subjects/Subject", nsmgr);
// return listSubject.Cou nt == 0
XmlNodeList listDefect =
doc.SelectNodes ("/EvsDB/Subjects/Subject/Defects/Defect", nsmgr); // return
listDefect.Coun t == 0
Can anybody tell hove to make it work?
--------
Thanks
Sharon
Comment