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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:58:38+00:00 2026-05-10T15:58:38+00:00

I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I’ll have

  • 0

I have an XML file that starts like this:

<Elements name='Entities' xmlns='XS-GenerationToolElements'> 

I’ll have to open a lot of these files. Each of these have a different namespace but will only have one namespace at a time (I’ll never find two namespaces defined in one xml file).

Using XPath I’d like to have an automatic way to add the given namespace to the namespace manager. So far, i could only get the namespace by parsing the xml file but I have a XPathNavigator instance and it should have a nice and clean way to get the namespaces, right?

— OR —

Given that I only have one namespace, somehow make XPath use the only one that is present in the xml, thus avoiding cluttering the code by always appending the namespace.

  • 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. 2026-05-10T15:58:39+00:00Added an answer on May 10, 2026 at 3:58 pm

    There are a few techniques that you might try; which you use will depend on exactly what information you need to get out of the document, how rigorous you want to be, and how conformant the XPath implementation you’re using is.

    One way to get the namespace URI associated with a particular prefix is using the namespace:: axis. This will give you a namespace node whose name is the prefix and whose value is the namespace URI. For example, you could get the default namespace URI on the document element using the path:

    /*/namespace::*[name()=''] 

    You might be able to use that to set up the namespace associations for your XPathNavigator. Be warned, though, that the namespace:: axis is one of those corners of XPath 1.0 that isn’t always implemented.

    A second way of getting that namespace URI is to use the namespace-uri() function on the document element (which you’ve said will always be in that namespace). The expression:

    namespace-uri(/*) 

    will give you that namespace.

    An alternative would be to forget about associating a prefix with that namespace, and just make your path namespace-free. You can do this by using the local-name() function whenever you need to refer to an element whose namespace you don’t know. For example:

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

    You could go one step further and test the namespace URI of the element against the one of the document element, if you really wanted:

    //*[local-name() = 'Element' and namespace-uri() = namespace-uri(/*)] 

    A final option, given that the namespace seems to mean nothing to you, would be to run your XML through a filter that strips out the namespaces. Then you won’t have to worry about them in your XPath at all. The easiest way to do that would be simply to remove the xmlns attribute with a regular expression, but you could do something more complex if you needed to do other tidying at the same time.

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

Sidebar

Related Questions

I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
Me again... I have an XML File that contains different categories which I would
I have an xml file providing data for a datagrid in Flex 2 that
I have an automatically generated XML file for the game that I run. It
I have a xsl file that is grabbing variables from xml and they seem
I have a PHP client that requests an XML file over HTTP (i.e. loads
I have a flash movie that loads images dynamically from an xml file. I
I have a T4 template that generates classes from an xml file. How can
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the
I have an XML file that I want to transform using an XSLT. It

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.