|
Subject:
|
C# XML--SelectSingleNode/SelectNodes is failing.
|
|
Posted By:
|
gijomk
|
Post Date:
|
8/28/2006 1:03:53 AM
|
I have one xml (which is HL7 format) as follows
----------------------------------
<?xml version="1.0" encoding="UTF-8"?> <PORP_IN000001 xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 PORP_IN000001.xsd" ITSVersion="XML_1.0"> <id/> <creationTime/> <interactionId/> <processingCode/> <processingModeCode/> <acceptAckCode/> <receiver> <device> <id/> </device> </receiver> <sender> <device> <id/> </device> </sender> <controlActProcess moodCode="EVN"> <subject> etc................................. ....................... ...... </controlActProcess> </PORP_IN000001> ----------------------------------
Please note that the above xml file is using the schema file "PORP_IN000001.xsd" and this file interally calls other schema files. There are 15 schema files using by this xml file. Only one schema file is directly refered in the xml file. All other schema files are called from the main schema file "PORP_IN000001.xsd"
I am trying to get the node from the xml file using c# code as follows
XmlDocument objXml=new XmlDocument(); objXml.Load(reader); oNsMgr = new XmlNamespaceManager(objXml.NameTable); oNsMgr.AddNamespace("", "urn:hl7-org:v3"); oNsMgr.AddNamespace("mif", "urn:hl7-org:v3/mif"); oNsMgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); XmlNode Node=objXml.SelectSingleNode("//receiver");
But here objXml.SelectSingleNode("//receiver") is returning null value. Actully i have one node already present in the xml file. Why the above query is failing. Can anybody help me?
Regards,
Gijo
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
8/29/2006 9:48:19 AM
|
Change this line of code
oNsMgr.AddNamespace("", "urn:hl7-org:v3");
to
oNsMgr.AddNamespace("we", "urn:hl7-org:v3");
that is provide an arbitrary prefix instead of leaving it empty and then change this line
XmlNode Node=objXml.SelectSingleNode("//receiver");
to
XmlNode Node=objXml.SelectSingleNode("//we:receiver");
Should work.
Regards Ankur
|