Wrox Programmer Forums
|
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition 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 December 2nd, 2008, 10:36 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Xpath is not Working.

Can somebody point out why this xpath is not working. I have also declared a namespacemanager but still XmlNodeList return null .



XML:

<manifest identifier="SingleCourseManifest" version="1.1"
          xmlns="..imsproject.org/xsd/imscp_rootv1p1p2"
          xmlns:adlcp="..adlnet.org/xsd/adlcp_rootv1p2"
          xmlns:xsi="..w3.org/2001/XMLSchema-instance"
...
          >
   <organizations default="B0">

      <organization identifier="B0">

         <title>Maritime Navigation</title>

         <item identifier="B100" isvisible="true">
            <title>Inland Rules of the Road (HTML Format)</title>

            <item identifier="S100001" identifierref="R_S100001" isvisible="true">
               <title>References and Lesson Objective</title>
            </item>

            <item identifier="B110" isvisible="true">
               <title>Steering & Sailing Rules</title>

               <item identifier="S110001" identifierref="R_S110001">
                  <title>Conduct of Vessels in any Condition of Visibility</title>
                  <adlcp:prerequisites type="aicc_script"><![CDATA[S100001]]></adlcp:prerequisites>
                  <adlcp:maxtimeallowed>0000:30:00.00</adlcp:maxtimeallowed>
               </item>

              .....


Code Behind

XmlDocument doc = new XmlDocument();
        doc.Load("c:\\Algebraic Expressions 2\\imsmanifest.xml");
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
       nsmgr.AddNamespace("adlcp", "url.adlnet.org/xsd/adlcp_rootv1p2");
        nsmgr.AddNamespace("xsd", "url.w3.org/2001/XMLSchema");
        nsmgr.AddNamespace("xsi", "url.w3.org/2001/XMLSchema-instance");
        nsmgr.AddNamespace("schemaLocation", "url.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd url.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd url.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd");
           nsmgr.PushScope();


        XmlNodeList Nodelst = doc.SelectNodes("//item", nsmgr);

        foreach (XmlNode node in Nodelst)
        {

            Response.Write(node.Value);
        }
 
Old December 3rd, 2008, 05:03 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The XPATH is working, but its the wrong XPATH.

Code:
<manifest identifier="SingleCourseManifest" version="1.1"
          xmlns="..imsproject.org/xsd/imscp_rootv1p1p2"
          xmlns:adlcp="..adlnet.org/xsd/adlcp_rootv1p2"
          xmlns:xsi="..w3.org/2001/XMLSchema-instance"


The clue is highlighted above - your XML elements are all in the default namespace. You haven't declared this namespace in your code, nor specified a namespace in the XPATH query.

Add the following line:

Code:
nsmgr.AddNamespace("ns01", "..imsproject.org/xsd/imscp_rootv1p1p2");
and then change the XPATH expression accordingly:

Code:
XmlNodeList Nodelst = doc.SelectNodes("//ns01:item", nsmgr);
/- Sam Judson : Wrox Technical Editor -/
 
Old December 4th, 2008, 09:13 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for ur reply.

i Solved it by adding the Namespace

nsmgr.AddNamespace("ns", "..imsproject.org/xsd/imscp_rootv1p1p2");

XmlNodeList Nodelst = doc.SelectNodes("//ns:item", nsmgr);









Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
help with XPath kend XSLT 2 July 15th, 2003 01:14 PM





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