all groups > dotnet xml > march 2007 >
You're in the

dotnet xml

group:

SelectSingleNode returns nothing. Namespace manager issue


SelectSingleNode returns nothing. Namespace manager issue need2scuba
3/22/2007 2:27:10 PM
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")
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>
Re: SelectSingleNode returns nothing. Namespace manager issue Bjoern Hoehrmann
3/23/2007 12:29:30 AM
* need2scuba wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

This does not work the way you think it would.

[quoted text, click to view]

Use

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

instead.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
RE: SelectSingleNode returns nothing. Namespace manager issue v-wywang NO[at]SPAM online.microsoft.com (
3/26/2007 12:00:00 AM
Hi,

[quoted text, click to view]
"http://www.imsproject.org/xsd/imscp_rootv1p1p2")

This statement means the default namespace for manifestNSManager is
"http://www.imsproject.org/xsd/imscp_rootv1p1p2".

[quoted text, click to view]

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
RE: SelectSingleNode returns nothing. Namespace manager issue v-wywang NO[at]SPAM online.microsoft.com (
3/28/2007 12:00:00 AM
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
AddThis Social Bookmark Button