470,855 Members | 1,277 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Namespace agnostic parser?

I need to be able to read some element values and populate some
element values for some XML documents submitted to a service, but I can
not predict the NameSpace in the documents.

I have been using the System.Xml.XmlDocument object with success for
a known NameSpace and using the NameSpaceManager object with it. Is
there a way to Load some XML into the DOM and manipulate it without
having to know the Namespace?
I need to read and write into the elements.

TIA
- Brian

Jun 16 '06 #1
3 1472
* br***********@gmail.com wrote in microsoft.public.dotnet.xml:
I need to be able to read some element values and populate some
element values for some XML documents submitted to a service, but I can
not predict the NameSpace in the documents.

I have been using the System.Xml.XmlDocument object with success for
a known NameSpace and using the NameSpaceManager object with it. Is
there a way to Load some XML into the DOM and manipulate it without
having to know the Namespace?


Your question does not really make sense to me, the XML parser and the
XmlDocument implementation should not care about namespaces in a way
that hinders you to apply generic processing. Could you give a minimal
example of what you would like to do and why it does not work?
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 17 '06 #2


br***********@gmail.com wrote:
I need to be able to read some element values and populate some
element values for some XML documents submitted to a service, but I can
not predict the NameSpace in the documents.

I have been using the System.Xml.XmlDocument object with success for
a known NameSpace and using the NameSpaceManager object with it. Is
there a way to Load some XML into the DOM and manipulate it without
having to know the Namespace?
I need to read and write into the elements.


If you know the element names but not the namespace then you could use
XPath expressions alike e.g.
//*[local-name() = 'the-element-name-here']
to find elements.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 17 '06 #3
Thanks all. Must have been my void of XPath knowledge at play here.
I was trying to write something like

SelectSingleNode("//ns1:OrderId")

without having to register "ns1" in the namespace manager object.

I have since resolved to use

string xPathPrefix = xmlDocument.DocumentElement.Prefix;

string xNameSpace = xmlDocument.DocumentElement.Attributes["xmlns:" +
xPathPrefix].Value;

And plowing forward into the NamespaceManager usage from there.
Allows me to not need to know the specifics of namespaces, atleast so
far.

Martin Honnen wrote:
br***********@gmail.com wrote:
I need to be able to read some element values and populate some
element values for some XML documents submitted to a service, but I can
not predict the NameSpace in the documents.

I have been using the System.Xml.XmlDocument object with success for
a known NameSpace and using the NameSpaceManager object with it. Is
there a way to Load some XML into the DOM and manipulate it without
having to know the Namespace?
I need to read and write into the elements.


If you know the element names but not the namespace then you could use
XPath expressions alike e.g.
//*[local-name() = 'the-element-name-here']
to find elements.
--

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


Jun 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Robert Warnestam | last post: by
1 post views Thread by toton | last post: by
3 posts views Thread by toton | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.