473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identifying all Namespace / Prefixes when reading an XML

How do I identify all of the namespace / prefix pairs associated with an XML
document I am reading?

Thanks for any help.

Paul
Jan 1 '06 #1
4 1858


PaulF wrote:
How do I identify all of the namespace / prefix pairs associated with an XML
document I am reading?


XPath has a namespace axis you could have your code walk. It depends on
how you read your XML document, with Xml(Text)Reader you do not have
XPath support. With XPathDocument or XmlDocument you do.
XPath expression is
//namespace::*
or (with duplicates removed)
//namespace::*[not(. = ../../namespace::*]
Note that the prefix xml is always bound to the namespace URI
http://www.w3.org/XML/1998/namespace.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 1 '06 #2
PaulF wrote:
How do I identify all of the namespace / prefix pairs associated with an XML
document I am reading?


Beware that namespace declarations can be nested and overriden. There is
no such thing as namespaces associated with XML document. Instead each
element in an XML document has associated namespaces. And each XML API
has its own facilities to identify namespaces. Which XML API are you
talking about?
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Jan 2 '06 #3
As is often the case what I ought to do is specify the business requirement I
am trying to address.

The business requirement is to process an XML (in fact a SOAP XML in a web
service) in a generic fashion. The XML is transformed passed to another web
service, the reply transformed and sent back. As new "products" (and
therefore new SOAP body XML structures) are processed using this web service
we want to be able to handle them by simply adding new transformations . I
know this sounds like a BizTalk solution but various (political) reasons mean
we have not gone down this road.

My requirement is therefore to be able to handle the differing incoming XML
messages in a generic fashion. The SOAP Headers will be relatively
consistent in structure whilst the SOAP body will vary by each function /
product.

The key area of concern is the SOAP Header. This uses the addressing (wsa)
and security (wsse) namespaces as well as several client specific namespaces.
I want to be able to read the nodes in the SOAP Header in an accurate,
consistent and robust manner.

Options appear to be:
1) Use serializable classes (generated from XSD schemas using XSD.exe) to
derserialize the incoming XML - potential downside is that the deserialize
process creates an intermediary temporary assembly with an associated
performance overhead
2) Essentially write our own deserialize process - but our code then needs
to explictily understand the namespaces being used in the incoming XML. Hence
my original question.
Paul

"Oleg Tkachenko [MVP]" wrote:
PaulF wrote:
How do I identify all of the namespace / prefix pairs associated with an XML
document I am reading?


Beware that namespace declarations can be nested and overriden. There is
no such thing as namespaces associated with XML document. Instead each
element in an XML document has associated namespaces. And each XML API
has its own facilities to identify namespaces. Which XML API are you
talking about?
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Jan 2 '06 #4
Martin

Thanks for this. One slight correction (in case anyone wants to use the
XPath) the duplicates removed version should read

//namespace::*[not(. = ../../namespace::*)]

note the closing bracket after the second *.
Paul

"Martin Honnen" wrote:


PaulF wrote:
How do I identify all of the namespace / prefix pairs associated with an XML
document I am reading?


XPath has a namespace axis you could have your code walk. It depends on
how you read your XML document, with Xml(Text)Reader you do not have
XPath support. With XPathDocument or XmlDocument you do.
XPath expression is
//namespace::*
or (with duplicates removed)
//namespace::*[not(. = ../../namespace::*]
Note that the prefix xml is always bound to the namespace URI
http://www.w3.org/XML/1998/namespace.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10100
by: Chris Spencer | last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in parsed xml files? The default behavior is to strip a document of all prefixes and then replace them autogenerated prefixes like ns0, ns1, etc. The correct behavior should be to write the file in the form that it was read, which it seems to do correctly for everything except namespace prefixes. The docs mention "proper" output can be achieved by using the Qname object,...
25
3097
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
2
3964
by: Wayne Wengert | last post by:
I am exporting an XML file based on a dataset using VB.NET. This works fine but the resulting xml file does not include namespace prefixes, which are required by another tool I am trying to use (Altova Stylevision). (See samples below) Stylevision won't see a file as valid unless it includes the namespace prefixes? I am confused about the whole namespace issue? It is not clear to me what the namespace really does here - or why it is needed?...
2
3487
by: steve | last post by:
Can someone point me to some information on namespace best practices? Questions I have are as follows: 1) Should I use .NET namespaces or URL, URI and URN's? Ie mycompany.mydivision.myapp vs http://www.mycompany.com/division/app? 2) Should I use namespace prefixes? I thought I read something using prefixes is a bad idea? 3) etc. Thanks in advance.
18
7739
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
1
1335
by: Hubidubi | last post by:
Hi, I would like to generate XML (struts code) from XML with XSL transformation. I run into problem when I wanted to use tags with prefixes, like <html:text />. I included namespace specification to the header: <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:html="struts">
4
7722
by: Samuel R. Neff | last post by:
I'm writing an xslt in vs.net 2003 and in order to get intellisense on the html content I added the default namespace declaration xmlns="http://schemas.microsoft.com/intellisense/ie5". However, even though I also have exclude-result-prefixes="#default" declared the default namespace is still outputted on the resulting document. <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0"...
3
2948
by: George | last post by:
I am currently developing an xbrl validation software that takes an xml instance file and a lot of schemas(xsd files) and validates it against the xsd files. I am using Visual basic in visual studio 2005. I have managed to cycle through the xml file , validate most of the variables, however, i have some problems with the namespaces of some attributes. For example, in my xml instance file, it says: <xbrldi:typedMember...
6
2252
by: Juha Nieminen | last post by:
Whenever one sees example C++ code basically anywhere, be it in a book, in a tutorial in the internet, in an online forum or whatever, I would estimate that at least in 99% of cases one sees the use of "using namespace std;" to get rid of that namespace. In fact, "using namespace ..." is very popular with all documentation and example code of most C++ libraries out there which use their own namespace. This raises the question why use...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.