472,952 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1748
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
4
by: AP | last post by:
Hi, I have a class that I wish to serialize to XML, part of which looks like this: public class TitleNotification { public string NoNameSpaceSchemaLocation =...
4
by: Krishna Tulasi via .NET 247 | last post by:
Hi, I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc: <Worksheet...
5
by: pneumoconi | last post by:
I've read a lot of posts on this subject each with a slightly different issue and from what I gather my code is fine. But its not. I'm trying to pull out the SQL query from a SQL report document...
2
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
5
by: David Thielen | last post by:
Hi; I set up my xml as follows: XmlDocument xml = new XmlDocument(); xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read)); XmlNamespaceManager context = new...
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);...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.