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 6537705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:38:57+00:00 2026-05-25T10:38:57+00:00

i wish to parse following XML <?xml version=1.0 encoding=UTF-8?> <product xmlns=http://products.org> <make xmlns=http://camera.org> <model>Camry</model>

  • 0

i wish to parse following XML

<?xml version="1.0" encoding="UTF-8"?>
<product xmlns="http://products.org"> 
    <make xmlns="http://camera.org">
 <model>Camry</model> 
</make>
 <make xmlns="http://tv.org">
   <model>Sony</model>
</make>
</product>

Code written to parse it

This is how i m writing Parsing Code

enter image description here
but in last i m getting null inxmlNode object. Can u tell what more to do .

  • 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-25T10:38:57+00:00Added an answer on May 25, 2026 at 10:38 am

    You can’t ignore namespaces in XPath.* The elements in your document all have non-blank namespace URI’s.

    Your question title indicates you’re on the right track: you need to explicitly bind the URI’s to prefixes using an XmlNamespaceManager, and use those prefixes in your path expressions.

    This program is tested against your input document

    using System;
    using System.Xml;
    
    public class XPathNamespace
    {
        public static void Main() {
    
            XmlDocument doc = new XmlDocument();
            doc.Load("test1.xml");
    
            XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable);
            xnm.AddNamespace("p", "http://products.org");
            xnm.AddNamespace("c", "http://camera.org");
            xnm.AddNamespace("t", "http://tv.org");
    
            ShowNode(doc.SelectSingleNode("/p:product", xnm));
            ShowNode(doc.SelectSingleNode("/p:product/c:make", xnm));
            ShowNode(doc.SelectSingleNode("/p:product/t:make", xnm));
        }
    
        private static void ShowNode(XmlNode node) {
            Console.WriteLine("<{0}> {1}",
                              node.LocalName, 
                              node.NamespaceURI);
        }
    }
    

    and it produces the following output

    <product> http://products.org
    <make> http://camera.org
    <make> http://tv.org
    

    Hope this helps.

    (*) This doesn’t mean you can’t ignore the exact namespace in your XPath. For example, you could match

    /*[local-name()='product']
    

    But that’s a workaround and illustrates that you still have to deal with the presence of a namespace somehow or other.

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

Sidebar

Related Questions

I wish to scrape the following wiki article: http://en.wikipedia.org/wiki/Periodic_table So that the output of
I have the following language i wish to parse using antlr 1.2.2. TEST <name>
I have the following collection ( see image ) . I wish to parse
I run an XPath in Java with the following xml and code: <?xml version=1.0
I wish to use xml and xsl to generate controls on an asp.net page.
I call an XML document three-layered if its structure is laid out as following:
I wish to parse a string and ensure that it is lower case. It
i have the following xml file <entry> <math marks>45</math marks> <eng marks>67</eng marks> <phy
I have some strange json that I cannot change, and I wish to parse
Possible Duplicate: Best methods to parse HTML with PHP I wish to get the

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.