Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2007

Tip: Looking for answers? Try searching our database.

SelectSingleNode returns nothing.  Namespace manager issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
need2scuba - 22 Mar 2007 22:27 GMT
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>
Bjoern Hoehrmann - 23 Mar 2007 00:29 GMT
* need2scuba wrote in microsoft.public.dotnet.xml:
>I have the following code snipet:
>
[quoted text clipped - 5 lines]
>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.
Signature

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/

WenYuan Wang - 26 Mar 2007 10:34 GMT
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
WenYuan Wang - 28 Mar 2007 09:28 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.