473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1823


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
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...
25
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...
2
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...
2
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...
18
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);...
1
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...
4
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,...
3
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...
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.