Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 2nd, 2007, 11:35 PM
=?Utf-8?B?amVmZl9nb21iYWxh?=
Guest
 
Posts: n/a
Default Xpath with Namespace retruns NULL, please help

I am using the following code to query for a single node, yet my results are
always NULL. Please help, I've tried everything adn I am unable to get a
result.

XmlDocument xml = new XmlDocument();
xml.LoadXml(strNLETSMessage);

XmlNamespaceManager nsmgr = new
XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("n", "http://www.nlets.org");
nsmgr.AddNamespace("j", "http://www.it.ojp.gov/jxdm/3.0");

XmlNode test =
xml.SelectSingleNode("/n:NLETS/n:NLETSInquiryMessage", nsmgr);

Sample XML file (the value of strNLETSMessage):

<n:NLETS version="3.00" xmlns:n="http://www.nlets.org "
xmlns:j="http://www.it.ojp.gov/jxdm/3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<n:NLETSInquiryMessage>
<n:NLETSInquiryHeader>
<n:DocumentUserID>
<j:ID>USER55</j:ID>
</n:DocumentUserID>
<n:DocumentPasswordText>123456</n:DocumentPasswordText>
<n:MessageKeyCode>RQ</n:MessageKeyCode>
</n:NLETSInquiryHeader>
</n:NLETSInquiryMessage>
</n:NLETS>

  #2  
Old March 3rd, 2007, 12:25 AM
Bjoern Hoehrmann
Guest
 
Posts: n/a
Default Re: Xpath with Namespace retruns NULL, please help

* jeff_gombala wrote in microsoft.public.dotnet.xml:
Quote:
>I am using the following code to query for a single node, yet my results are
>always NULL. Please help, I've tried everything adn I am unable to get a
>result.
>
>XmlDocument xml = new XmlDocument();
xml.LoadXml(strNLETSMessage);
>
XmlNamespaceManager nsmgr = new
>XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("n", "http://www.nlets.org");
nsmgr.AddNamespace("j", "http://www.it.ojp.gov/jxdm/3.0");
>
XmlNode test =
>xml.SelectSingleNode("/n:NLETS/n:NLETSInquiryMessage", nsmgr);
>
>Sample XML file (the value of strNLETSMessage):
>
><n:NLETS version="3.00" xmlns:n="http://www.nlets.org "
^

There is a trailing space in this line, does it work if you remove the
space?
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles