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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:02:07+00:00 2026-06-07T12:02:07+00:00

I want to be able to get all namespace information from a given XML

  • 0

I want to be able to get all namespace information from a given XML File.

So for example, if the input XML File is something like:

<ns1:create xmlns:ns1="http://predic8.com/wsdl/material/ArticleService/1/">
   <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
      <ns1:id>1</ns1:id>
      <description>bar</description>
      <name>foo</name>
      <ns1:price>
         <amount>00.00</amount>
         <currency>USD</currency>
      </ns1:price>
      <ns1:price>
         <amount>11.11</amount>
         <currency>AUD</currency>
      </ns1:price>
   </ns1:article>
   <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
      <ns1:id>2</ns1:id>
      <description>some name</description>
      <name>some description</name>
      <ns1:price>
         <amount>00.01</amount>
         <currency>USD</currency>
      </ns1:price>
   </ns1:article>
</ns1:create>

I would like to expect an output that looks something like this (in this case comma-separated):

create, ns1, http://predic8.com/wsdl/material/ArticleService/1/
article, ns1, http://predic8.com/material/1/
price, ns1, http://predic8.com/material/1/
id, ns1, http://predic8.com/material/1/

Important notes:

It is important that we also consider sub-nodes which are defined within a specific namespace, but whose definition may be defined at a higher node. For example, we would still like to pick up the node ns1:id, where we need to trace back to the parent node ns1:article to discover that the namespace url is xmlns:ns1='http://predic8.com/material/1/

I am implementing in Java, so I would not mind either a Java-based solution, or even a XSLT-based solution might seem appropriate.

  • 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-06-07T12:02:10+00:00Added an answer on June 7, 2026 at 12:02 pm

    Further developed the XPath expression proposed by Michael Kay (seems actually as a simplification) to also process unprefixed element names that belong to a default namespace:

    distinct-values(//*[namespace-uri()]
                        /concat(local-name(),
                                ', ',
                                substring-before(name(), ':'),
                                ', ',
                                namespace-uri(),
                                '&#xA;'
                                )
                    )
    

    When this XPath expression is evaluated on the following document (the provided one but with an added element that is in a default namespace):

    <ns1:create xmlns:ns1="http://predic8.com/wsdl/material/ArticleService/1/">
        <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
            <ns1:id>1</ns1:id>
            <description>bar</description>
            <name>foo</name>
            <ns1:price>
                <amount>00.00</amount>
                <currency>USD</currency>
            </ns1:price>
            <ns1:price>
                <amount>11.11</amount>
                <currency>AUD</currency>
            </ns1:price>
        </ns1:article>
        <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
            <ns1:id>2</ns1:id>
            <description>some name</description>
            <name>some description</name>
            <ns1:price>
                <amount>00.01</amount>
                <currency>USD</currency>
            </ns1:price>
            <quality xmlns="my:q">high</quality>
        </ns1:article>
    </ns1:create>
    

    the wanted, correct result is produced:

     create, ns1, http://predic8.com/wsdl/material/ArticleService/1/
     article, ns1, xmlns:ns1='http://predic8.com/material/1/
     id, ns1, xmlns:ns1='http://predic8.com/material/1/
     price, ns1, xmlns:ns1='http://predic8.com/material/1/
     quality, , my:q
    

    A further, slight improvement is also to produce the namespace data for attribute names:

    distinct-values(//(*|@*)[namespace-uri()]
                        /concat(if(. intersect ../@*)
                                  then '@'
                                  else (),
                                local-name(),
                                ', ',
                                substring-before(name(), ':'),
                                ', ',
                                namespace-uri(),
                                '&#xA;'
                                )
                    )
    

    When this XPath expression is evaluated on the following XML document (the previous one (above) with added an xml:lang attribute on one of the article elements):

    <ns1:create xmlns:ns1="http://predic8.com/wsdl/material/ArticleService/1/">
        <ns1:article xml:lang="en-us" xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
            <ns1:id>1</ns1:id>
            <description>bar</description>
            <name>foo</name>
            <ns1:price>
                <amount>00.00</amount>
                <currency>USD</currency>
            </ns1:price>
            <ns1:price>
                <amount>11.11</amount>
                <currency>AUD</currency>
            </ns1:price>
        </ns1:article>
        <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/">
            <ns1:id>2</ns1:id>
            <description>some name</description>
            <name>some description</name>
            <ns1:price>
                <amount>00.01</amount>
                <currency>USD</currency>
            </ns1:price>
            <quality xmlns="my:q">high</quality>
        </ns1:article>
    </ns1:create>
    

    again the correct result is produced:

     create, ns1, http://predic8.com/wsdl/material/ArticleService/1/
     article, ns1, xmlns:ns1='http://predic8.com/material/1/
     @lang, xml, http://www.w3.org/XML/1998/namespace
     id, ns1, xmlns:ns1='http://predic8.com/material/1/
     price, ns1, xmlns:ns1='http://predic8.com/material/1/
     quality, , my:q
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to achieve the following using guice/gin: Get all sort
I want to be able to get something similar to this.. I want to
HI all, i want to connect to remote Linux machine and get response from
I want to be able to get all the value pairs under a location
I have an XML-like file: <p>something</p> <ac:image> <ri:attachment ri:filename=IMAGE.PNG /> </ac:image> <ac:macro ac:name=screenshot> <ac:default-parameter>IMAGE.ss</ac:default-parameter>
I want to be able to get the current bound object in the ItemTemplate
I want to be able to get different array values in my ajax callback
I'm creating a chrome extension, and want to be able to get a profile
I want to make my server to be able to get the name of
I want to position two ImageViews horizontally, but I am not able to get

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.