473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SelectSingleNode returns nothing. Namespace manager issue

I have the following code snipet:

....
_xmldocManifest.Load(strManifestAbsolutePath)

Dim manifestNSManager As XmlNamespaceManager = New
XmlNamespaceManager(_xmldocManifest.NameTable)
manifestNSManager.AddNamespace(String.Empty,
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")
manifestNSManager.AddNamespace("ns",
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")
manifestNSManager.AddNamespace("adlcp",
"http://www.adlnet.org/xsd/adlcp_rootv1p2")
manifestNSManager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema")
manifestNSManager.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance")
manifestNSManager.AddNamespace("schemaLocation",
"http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd")
manifestNSManager.PushScope()

However the following statement returns nothing (for the XML below):

_xmldocManifest.SelectSingleNode("//metadata", manifestNSManager)

But if I remove the first attribute of the manifest node
(xmlns=http://www.imsproject.org/xsd/imscp_rootv1p1p2) it works fine and I
can navigate the xml document with no problems. Any thoughts?

Note the following state works fine without removing the attribute:

_xmldocManifest.SelectSingleNode("//adlcp:location", manifestNSManager)
XML SNIPET:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2
imscp_rootv1p1p2.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2
adlcp_rootv1p2.xsd"
identifier="x-ims-plirid-v0.DUNS.05-107-9929.mfstid.en_US_11953">
<metadata>
<schema>ADL SCORM</schema>
<schemaversion>1.2</schemaversion>
<adlcp:location>en_US_11953/en_US_11953.xml</adlcp:location>
</metadata>
</manifest>

Mar 22 '07 #1
3 7401
* need2scuba wrote in microsoft.public.dotnet.xml:
>I have the following code snipet:

...
_xmldocManifest.Load(strManifestAbsolutePath)

Dim manifestNSManager As XmlNamespaceManager = New
XmlNamespaceManager(_xmldocManifest.NameTable)
manifestNSManager.AddNamespace(String.Empty,
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")
This does not work the way you think it would.
>manifestNSManager.AddNamespace("ns",
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")
>_xmldocManifest.SelectSingleNode("//metadata", manifestNSManager)
Use

_xmldocManifest.SelectSingleNode("//ns:metadata", manifestNSManager)

instead.
--
Björn Höhrmann · mailto:bj****@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/
Mar 22 '07 #2
Hi,
>manifestNSManager.AddNamespace(String.Empty,
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")

This statement means the default namespace for manifestNSManager is
"http://www.imsproject.org/xsd/imscp_rootv1p1p2".
>_xmldocManifest.SelectSingleNode("//metadata", manifestNSManager)
If the XPath expression does not include a prefix, it is assumed that the
namespace URI is the empty namespace. (xlmns="") Otherwise, if your XML
includes a default namespace, you must add a prefix and namespace URI to
it; otherwise, you will not get a selected node.

As Bjoern said, you can use
_xmldocManifest.SelectSingleNode("//ns:metadata", manifestNSManager)
instead.

Hope this helps. Please feel free to reply here if you have anything
unclear. I'm glad to assist you.

Have a great day,
Sincerely,
Wen Yuan

Mar 26 '07 #3
Hello,

Have you resolved the issue now?
If it still persists or you have anything unclear, please don't hesitate to
update here. I'm glad to assis you.

Have a great day,
Sincerely,
Wen Yuan

Mar 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
3
by: Demetri | last post by:
I'm getting the following error: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function. On the following line of code: XmlNode sNode =...
1
by: K. Wilder | last post by:
I'm trying to get the value of a single node using SelectSingleNode and I get the NullReference Error. Example: I want to get the URL in the HTML element but the GetHTMLPath() function fails on...
5
by: Colin Young | last post by:
I have the following XML ('Offer' only appears once in the XML): <OfferSheetXML xmlns="http://localhost/GBWPipeline/OfferSheetSchema.xsd"> <Offer> <OfferSheetId>31</OfferSheetId> </Offer>...
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
0
by: Martin | last post by:
Hi, I am using xmldocument.selectsinglenode to query an xml document. This works perfectly when the document to be queried has no namespace, however as some as i put a namespace in then null is...
4
by: Robert Ludig | last post by:
My question is somewhat related to the previous question in this newsgroup: ...
2
by: Rick63 | last post by:
I am using VB .Net 2003 XML namespace to get specified values from an XML document. I have used Stylus Studio 2007 to verify that my XPath query is valid and returns the node/nodes I am looking for....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.