472,139 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 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 1727


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Chris Spencer | last post: by
25 posts views Thread by kj | last post: by
2 posts views Thread by Wayne Wengert | last post: by
2 posts views Thread by steve | last post: by
1 post views Thread by Hubidubi | last post: by
reply views Thread by leo001 | last post: by

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.