473,396 Members | 1,846 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,396 software developers and data experts.

Specifying namespace prefix?

Hi,

I'm trying to write a routine to extract results from a web service written
in VS 2005 using XPath, however VS doesn't put a prefix on result namespaces
by default, so in the output from a service such as

<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MyTest5Response xmlns="adam">
<MyTest5Result>
<testInt>9</testInt>
<testStruct>
<z>
<MyStruct><x>0</x><y>0</y><z>0</z></MyStruct>
<MyStruct><x>0</x><y>0</y><z>0</z></MyStruct>
</z>
</testStruct>
</MyTest5Result>
</MyTest5Response>
</soap:Body>
</soap:Envelope>

I can not use XPath to extract anything lower than soap:Body by name, e.g.
/soap:Envelope/soap:Body/MyTest5Response is invalid as MyTest5Response has no
namespace prefix.

Does anyone know if either

1) I'm wrong, and there is a valid XPath to the response / results nodes
2) It's possible to specify a prefix which will be output by the web service
3) There's an easy XSLT transform I could apply after calling the web
service to add a prefix (I have no knowledge of transforms myself); this
would be better, as I'll also have to interface with services written by
other companies.

The consumer program is not being produced in any VS languages, so I can't
use anything like XmlNamespaceManager or other .Net / VS features.
Thanks in advance,

Adam
Oct 16 '06 #1
1 2244
"Adam Eccleshall" <Ad************@discussions.microsoft.comwrote in
message news:3C**********************************@microsof t.com...
Hi,

I'm trying to write a routine to extract results from a web service
written
in VS 2005 using XPath, however VS doesn't put a prefix on result
namespaces
by default, so in the output from a service such as

<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MyTest5Response xmlns="adam">
You need to create an XmlNamespaceManager object and add the namespace to
it. Use whatever prefix you like when you add it. You then use that prefix
in your XPath queries. This is the same technique you'd use if the XML had
included a prefix. For instance, if you need to reference the <soap:Body>
element, you can do:

XmlNamespaceManager ns = new XmlNamespaceManager();
ns.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
XmlNode body = document.SelectSingleNode("//SOAP-ENV:Body", ns);

John

P.S. Always remember that prefixes only mean what someone decides they mean.
They always are just an abbreviation of a namespace. It's the namespace that
matters.
Oct 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
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: 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...
3
by: JT | last post by:
Hi all, I have a pretty basic question... I have a method (below) which uses ExecuteXMLReader to load the output from a FOR XML Explicit stored procedure into an XML document, and then save the...
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);...
0
by: supercodepoet | last post by:
What I have is a .NET 2.0 C# web service for quoting a tax rate. The current response wrapped in the SOAP envelope and body is : <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.