473,473 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML namespaces and prefix

I am trying to use xpath queries on an xmldocument passed to my web service.
The document nodes have namespace prefixes. How can I programatically
create an xpath query and run it assuming that the namespace and prefix
could potentially change?

Here is an example of my xml (from an infopath form in this case, but could
be from any application)

<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.52" productVersion="11.0.6357"
PIVersion="1.0.0.0"
href="http://testmachine/infopathforms/DocumentLibraryTest.xsn"
name="urn:schemas-microsoft-com:office:infopath:DocumentLibraryTest:-myXSD-2005-07-28T21-22-28"
?><?mso-application progid="InfoPath.Document"?>
<my:Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-28T21:22:28"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xml:lang="en-us">
<my:Header>
<my:PHN>1234</my:PHN>
</my:Header>
<my:Footer>
<my:DateCompleted>2005-08-04</my:DateCompleted>
<my:CompletedBy>123</my:CompletedBy>
</my:Footer>
<my:Description>
<my:Text></my:Text>
</my:Description>
<my:Extra>
<my:Active>false</my:Active>
<my:ExtraText></my:ExtraText>
</my:Extra>
</my:Form>
Nov 23 '05 #1
1 1964
Hi,

Ehh.. if you say "assuming that the namespace and prefix could
potentially change" it is a strange construct. If a namespace would
'suddenly change', all clients would have problems. This is usualy a
'versioning' step that happened. My advise is ALWAYS change the
namespace uri, if the schema constructs change. But, maintain the
precious versions of the schema. Do not overwrite the old one.
For this example you should do something like:
(From the top of my head, forgive me any typo's)

XmlNamespaceManager xNS = new XmlNamespaceManager( new NameTable () );
xNS.AddNamespace( "prefix", "namespaceUri" );

XmlDocument xDoc = new XmlDocument();
xDoc.Load( @"C:\temp\somexml.xml" );

XmlNodeList xNL = xDoc.DocumentElement.SelectNodes (
"prefix:MainRoot/prefix:SomeChild" );
Hope this helps,

Marvin Smit.
On Fri, 29 Jul 2005 11:06:57 -0700, "Jeremy Chapman" <me@here.com>
wrote:
I am trying to use xpath queries on an xmldocument passed to my web service.
The document nodes have namespace prefixes. How can I programatically
create an xpath query and run it assuming that the namespace and prefix
could potentially change?

Here is an example of my xml (from an infopath form in this case, but could
be from any application)

<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.52" productVersion="11.0.6357"
PIVersion="1.0.0.0"
href="http://testmachine/infopathforms/DocumentLibraryTest.xsn"
name="urn:schemas-microsoft-com:office:infopath:DocumentLibraryTest:-myXSD-2005-07-28T21-22-28"
?><?mso-application progid="InfoPath.Document"?>
<my:Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-28T21:22:28"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xml:lang="en-us">
<my:Header>
<my:PHN>1234</my:PHN>
</my:Header>
<my:Footer>
<my:DateCompleted>2005-08-04</my:DateCompleted>
<my:CompletedBy>123</my:CompletedBy>
</my:Footer>
<my:Description>
<my:Text></my:Text>
</my:Description>
<my:Extra>
<my:Active>false</my:Active>
<my:ExtraText></my:ExtraText>
</my:Extra>
</my:Form>


Nov 23 '05 #2

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

Similar topics

5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
15
by: Stuart | last post by:
I work in a small company with developers who do not like to use "new" features when they find the old ones sufficient. e.g. given a choice between a class and a namespace, they'll pick class. ...
5
by: Steve Jorgensen | last post by:
I was having a bear of a time today trying to figure out some inconsistent behavior selecting nodes from and MSXML DOM document, so I distilled the issue down to a trivial test demonstrating the...
3
by: Colin Green | last post by:
I have come across what seems like a failing in the .Net XML classes. Many people have posted requesting how to write an XPath query with namespace prefixes that works. The solution shown in all...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
36
by: Wilfredo Sánchez Vega | last post by:
I'm having some issues around namespace handling with XML: >>> document = xml.dom.minidom.Document() >>> element = document.createElementNS("DAV:", "href") >>> document.appendChild(element)...
5
by: printdude1968 | last post by:
Hi Everyone... I'm a newbie to this stuff so bear with me. I have a well formed xml document (I use jdom to verify) <?xml version="1.0" encoding="ISO-8859-1"?> <print-control>...
7
by: Grant Robertson | last post by:
As I am learning about XML I seen that xmlns is used with a colon after it as if it were a namespace itself. However, I have never seen a URI given for it. Is "xmlns" a sort of predefined word in...
0
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
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
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...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.