473,379 Members | 1,302 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,379 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 1822


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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.