468,247 Members | 1,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to determine assigned namespace prefix

Hello,

I'm receiving a response XML doc and need to know which letter was assigned
by the server to a namespace.

For example, here's a doc that I got returned to me. I need to extract the
"subject", so I need to know that "e" was assigned because I'm using the
..Net "GetElementsByTagName" method: (GetElementsByTagName("e:subject")):

<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-188741245e/"
xmlns:e="urn:schemas:httpmail:" xmlns:f="urn:schemas:mailheader:"
xmlns:c="xml:" xmlns:d="urn:schemas:calendar:" xmlns:a="DAV:">
<a:response>
<a:href>http://mail.mydomain.com/exchdav/milop/Installations/APPT2006699141633.eml</a:href>
<a:propstat>
<a:status>HTTP/1.1 200 OK</a:status>
<a:prop>
<d:location>HOME</d:location>
<e:subject>SUBJECT</e:subject>
<d:contact>MILOP CONTACT</d:contact>
<d:dtstart b:dt="dateTime.tz">2006-06-09T08:00:00.000Z</d:dtstart>
<d:dtend b:dt="dateTime.tz">2006-06-09T08:00:00.000Z</d:dtend>
<d:instancetype b:dt="int">0</d:instancetype>
<f:message-id>2006-06-09-09.13.55.732000</f:message-id>
</a:prop>
</a:propstat>
<a:propstat>
<a:status>HTTP/1.1 404 Resource Not Found</a:status>
<a:prop>
<d:busystatus/>
<f:content-location/>
</a:prop>
</a:propstat>
</a:response>
</a:multistatus>
Is there a quick XPath expression or something in System.XML that will aid
in this?

Thanks in advance,

Mike
Jun 9 '06 #1
3 1593
Nevermind, I found it: GetPrefixOfNamespace.

Couldn't be more simple.

"MikeL" <mi***@slomins.com> wrote in message
news:uI**************@TK2MSFTNGP03.phx.gbl...
Hello,

I'm receiving a response XML doc and need to know which letter was
assigned by the server to a namespace.

For example, here's a doc that I got returned to me. I need to extract the
"subject", so I need to know that "e" was assigned because I'm using the
.Net "GetElementsByTagName" method: (GetElementsByTagName("e:subject")):

<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-188741245e/"
xmlns:e="urn:schemas:httpmail:" xmlns:f="urn:schemas:mailheader:"
xmlns:c="xml:" xmlns:d="urn:schemas:calendar:" xmlns:a="DAV:">
<a:response>

<a:href>http://mail.mydomain.com/exchdav/milop/Installations/APPT2006699141633.eml</a:href>
<a:propstat>
<a:status>HTTP/1.1 200 OK</a:status>
<a:prop>
<d:location>HOME</d:location>
<e:subject>SUBJECT</e:subject>
<d:contact>MILOP CONTACT</d:contact>
<d:dtstart b:dt="dateTime.tz">2006-06-09T08:00:00.000Z</d:dtstart>
<d:dtend b:dt="dateTime.tz">2006-06-09T08:00:00.000Z</d:dtend>
<d:instancetype b:dt="int">0</d:instancetype>
<f:message-id>2006-06-09-09.13.55.732000</f:message-id>
</a:prop>
</a:propstat>
<a:propstat>
<a:status>HTTP/1.1 404 Resource Not Found</a:status>
<a:prop>
<d:busystatus/>
<f:content-location/>
</a:prop>
</a:propstat>
</a:response>
</a:multistatus>
Is there a quick XPath expression or something in System.XML that will aid
in this?

Thanks in advance,

Mike

Jun 9 '06 #2


MikeL wrote:
I'm receiving a response XML doc and need to know which letter was assigned
by the server to a namespace.


For your example you could load the XML file into an XmlDocument
instance and then call
xmlDocumentInstance.DocumentElement.GetPrefixOfNam espace("urn:schemas:httpmail:")
which would yield the string "e".
If all namespace declarations are on the document element/root element
node simply using GetPrefixOfNamespace on that DocumentElement should
solve the problem in general.
In theory of course a descendant node of the document element could
redefine the prefix but that was not the case in your example.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 9 '06 #3
Thanks Martin.

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:OL**************@TK2MSFTNGP04.phx.gbl...


MikeL wrote:
I'm receiving a response XML doc and need to know which letter was
assigned by the server to a namespace.


For your example you could load the XML file into an XmlDocument instance
and then call
xmlDocumentInstance.DocumentElement.GetPrefixOfNam espace("urn:schemas:httpmail:")
which would yield the string "e".
If all namespace declarations are on the document element/root element
node simply using GetPrefixOfNamespace on that DocumentElement should
solve the problem in general.
In theory of course a descendant node of the document element could
redefine the prefix but that was not the case in your example.
--

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

Jun 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by kj | last post: by
3 posts views Thread by Mike Dickens | last post: by
4 posts views Thread by Krishna Tulasi via .NET 247 | last post: by
5 posts views Thread by pneumoconi | last post: by
2 posts views Thread by Manoj G | last post: by
5 posts views Thread by David Thielen | last post: by
2 posts views Thread by scottpet | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.