Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2006, 01:03 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gijomk Send a message via Yahoo to gijomk
Default C# XML--SelectSingleNode/SelectNodes is failing.

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

 
Old August 29th, 2006, 09:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Change this line of code

      
Code:
oNsMgr.AddNamespace("", "urn:hl7-org:v3");


to

      
Code:
oNsMgr.AddNamespace("we", "urn:hl7-org:v3");


that is provide an arbitrary prefix instead of leaving it empty and
then change this line

      
Code:
XmlNode Node=objXml.SelectSingleNode("//receiver");


to

      
Code:
XmlNode Node=objXml.SelectSingleNode("//we:receiver");


Should work.

Regards
Ankur





Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectSingleNode throwing exception: anup_daware .NET Framework 2.0 1 February 3rd, 2008 12:04 PM
SelectNodes, SelectSingleNode weirdness dantell BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 October 19th, 2006 12:39 PM
C# XML--SelectSingleNode/SelectNodes is failing. gijomk XML 2 August 28th, 2006 03:28 AM
XML Namespace and ASP SelectNodes werD420 Classic ASP XML 1 August 13th, 2005 04:41 AM
MSXML - SelectNodes and XPath billy_bob_the_3rd Beginning VB 6 2 March 10th, 2005 06:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.