Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:19+00:00 2026-05-26T15:52:19+00:00

So, I need to be able to parse xml files that could include namespace

  • 0

So, I need to be able to parse xml files that could include namespace prefixes. I’ve tried doing this with a sample file and it gives me back null when trying to get a nodelist, even when I specify a node that has no attribute prefixes.

I’ve been trying to research this and it keeps coming back to the fact that without the namespace prefix defined, it won’t work, so I’ve added code that I thought would do this, but it’s still giving the same results. Here’s some code I’ve added:

protected void Page_Load(object sender, EventArgs e)
{
    xml.Load(Server.MapPath("~/SomeLesson/imsmanifest.xml"));
    populateBaseNodes();
}

private void populateBaseNodes()
{
    treeViewMenu.Nodes.Clear(); // Clear any existing items
    TreeNode treenode = new TreeNode();
    treenode.Text = "organizations";
    XmlNodeList baseNodeList;

    string xmlns = xml.DocumentElement.Attributes["xmlns"].Value;
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
    nsmgr.AddNamespace("adlcp", "http://www.adlnet.org/xsd/adlcp_v1p3");
    nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    nsmgr.AddNamespace("imscp", "http://www.w3.org/2001/XMLSchema-instance");
    nsmgr.AddNamespace("imsss", "http://www.w3.org/2001/XMLSchema-instance");
    nsmgr.AddNamespace("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");

    baseNodeList = xml.SelectNodes("/manifest/organizations/organization/item", nsmgr);

    TextBox1.Text = baseNodeList.Count.ToString();

    foreach (XmlNode xmlnode in baseNodeList)
    {
        TreeNode treeNodeCatalog = new TreeNode();
        treeNodeCatalog.Text = xmlnode.Attributes["identifier"].Value;
        treeNodeCatalog.SelectAction = TreeNodeSelectAction.Expand;
        treeViewMenu.Nodes.Add(treeNodeCatalog);
    }

    treeViewMenu.CollapseAll();
}

(marc_s) Here’s the XML in question that needs to be parsed:

<manifest identifier="Navigating_in_QuickBooks_-_Introduction_MANIFEST" version="1.3"
  xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:imscp="http://www.imsglobal.org/xsd/imscp_v1p1"
    xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" 
    xmlns:imsss="http://www.imsglobal.org/xsd/imsss"
    xsi:schemaLocation=" http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd
                         http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd
                         http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd 
                         http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd
                         http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd">

  <metadata>  
     <!-- not relevant here ... -->
  </metadata>
  <organizations default="TOC1">
     <organization identifier="TOC1">
        <title>Navigating in QuickBooks - Introductory Lesson</title>
        <item identifier="I_SCO0" identifierref="SCO0"> 
            <title>Navigating in QuickBooks - Introductory Lesson</title>
        </item>
     </organization>
   </organizations>
   <resources>
     <!-- not relevant here ... -->
   </resources>
</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:52:20+00:00Added an answer on May 26, 2026 at 3:52 pm

    You’re not showing us what your XML looks like – but two comments:

    1. you don’t need to add the xsi prefix, and I’m not sure what the schemaLocation prefix is supposed to do ….

    2. when you’ve defined the schema prefixes, you also need to use those prefixes in your XPath, of course!

    Again, not knowing what your XML structure looks like, I cannot really tell what you need – but something along the lines of:

     baseNodeList = xml.SelectNodes("/adlcp:manifest/adlcp:organizations/adlcp:organization/imscp:item", nsmgr);
    

    or whatever other XML namespace prefixes your source XML requires.

    Update: seeing your XML makes it clearer: see the root node – it has a default XML namespace (the one with xmlns="...." and no explicit prefix):

    <manifest identifier="Navigating_in_QuickBooks_-_Introduction_MANIFEST" version="1.3"
         xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"  <=== DEFAULT namespace!!!
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:imscp="http://www.imsglobal.org/xsd/imscp_v1p1"
         xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" 
         xmlns:imsss="http://www.imsglobal.org/xsd/imsss"
        ................>
    

    That means: ALL your subsequent nodes that don’t have a specific XML prefix will be in that default namespace.

    Unfortunately, .NET XML parsing has problem with defining a default namespace without prefix – so my best solution is to create a namespace with a prefix for the default namespace, and then use it:

    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
    
    // add default namespace, with a prefix for .NET 
    nsmgr.AddNamespace("ns", "http://www.imsglobal.org/xsd/imscp_v1p1");
    
    baseNodeList = 
       xml.SelectNodes("/ns:manifest/ns:organizations/ns:organization/ns:item", nsmgr);
    

    Do you get any results now??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After an AJAX query, a XML file is returned. I'm able to parse that
I've got a configuration xml file that I need to parse for values before
I am trying to parse the XML file in R, so that I can
I do not need to edit any XML-file or anything, this is only for
So I have an XML file that looks a little like this <xml> <post>
I am parsing an xml file using jQuery and need to be able to
I want to parse some XML-file in Qt, but that file is located at
I have an XML file that I want to parse into a database in
i need to find away to parse html and css layout to be able
I need to be able to load the entire contents of a text file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.