Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2008, 10:36 PM
Registered User
 
Join Date: Dec 2008
Location: , , .
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);
        }
  #2 (permalink)  
Old December 3rd, 2008, 05:03 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
  #3 (permalink)  
Old December 4th, 2008, 09:13 PM
Registered User
 
Join Date: Dec 2008
Location: , , .
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);




 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.