SelectSingleNode and Namespace

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C54429.49A1B710
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources =
xmlns=3Dhttp://schemas.microsoft.com/RtcServer/2002/11/dbimpexp =
Version=3D"3">

        <HomedResource UserAtHost=3D"PBoul@team.de" Enabled=3D"1" =
VersionPermission=3D"10"  =20

          VersionContact=3D"25" DisplayName=3D"Boullay, Peter" =
Email=3D"PBoul@team.de" Phone=3D"+88 =20

           09 75" LastRegisterTime=3D"2005-03-29T09:36:00"=20

           =
xmlns=3D"http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">

               <ContactGroups>

                      <ContactGroup Number=3D"1" DisplayName=3D"~">

                      </ContactGroup>

               </ContactGroups>

.........



When I then use=20



        Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)

        Dim node As XmlNode

        xmlDoc.Load(pfad)

        Dim nodeX As XmlNode =3D =
xmlDoc.SelectSingleNode("/HomedResources", xmlNsM)



The SelectSingleNode Method doesn't find any node!



But when I remove the xmlns-Attribute on the top of  the XML-Document =
SelectSingle Node find a node.



Any Idea how to use SelectSingleNode with Namespaces?



thanx



Marcel

------=_NextPart_000_0006_01C54429.49A1B710
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2627" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I use a XML-Doc with a Namespace like =
the following=20
example:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><FONT =
face=3DArial><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">&lt;</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: maroon; mso-ansi-language: =
EN-GB">HomedResources</SPAN><SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; =
mso-ansi-language: EN-GB">=20
</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">xmlns</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3Dhttp://schemas.microsoft.com/RtcServer/2002/11/dbimpexp</SPAN><=
SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; =
mso-ansi-language: EN-GB">=20
</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">Version</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3D"3"&gt;<?xml:namespace=20
prefix =3D o ns =3D "urn:schemas-microsoft-com:office:office"=20
/><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
face=3DArial><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;</SPAN><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;</SPAN><SPAN=20
style=3D"COLOR: blue">&lt;</SPAN><SPAN=20
style=3D"COLOR: maroon">HomedResource</SPAN><SPAN style=3D"COLOR: =
fuchsia">=20
</SPAN><SPAN style=3D"COLOR: red">UserAtHost</SPAN><SPAN=20
style=3D"COLOR: blue">=3D"PBoul@team.de"</SPAN><SPAN style=3D"COLOR: =
fuchsia">=20
</SPAN><SPAN style=3D"COLOR: red">Enabled</SPAN><SPAN=20
style=3D"COLOR: blue">=3D"1"</SPAN><SPAN style=3D"COLOR: fuchsia"> =
</SPAN><SPAN=20
style=3D"COLOR: red">VersionPermission</SPAN><SPAN=20
style=3D"COLOR: blue">=3D"10"</SPAN><SPAN style=3D"COLOR: fuchsia"> =
<SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;</SPAN><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><FONT =
face=3DArial><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; mso-ansi-language: =
EN-GB"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN></SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">VersionContact</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3D"25"</SPAN><SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; =
mso-ansi-language: EN-GB">=20
</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">DisplayName</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3D"Boullay,=20
Peter"</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; mso-ansi-language: EN-GB"> =
</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">Email</SPAN><SPAN=20
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3D"PBoul@team.de"</SPAN><SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: fuchsia; =
mso-ansi-language: EN-GB">=20
</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: red; mso-ansi-language: =
EN-GB">Phone</SPAN><SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB">=3D"+88=20
<SPAN style=3D"mso-spacerun: =
yes">&nbsp;</SPAN><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><FONT =
face=3DArial><SPAN=20
lang=3DEN-GB style=3D"FONT-SIZE: 10pt; COLOR: blue; mso-ansi-language: =
EN-GB"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN></SPAN><SPAN style=3D"FONT-SIZE: 10pt; COLOR: blue">09 =
75"</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: fuchsia"> </SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: red">LastRegisterTime</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: =
blue">=3D"2005-03-29T09:36:00"</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: fuchsia"> <o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><FONT =
face=3DArial><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: fuchsia"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN></SPAN><SPAN style=3D"FONT-SIZE: 10pt; COLOR: =
red">xmlns</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: =
blue">=3D"http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp"&gt;<o:=
p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
face=3DArial><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">&lt;</SPAN><SPAN=20
style=3D"COLOR: maroon">ContactGroups</SPAN><SPAN=20
style=3D"COLOR: blue">&gt;<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
face=3DArial><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN=20
style=3D"COLOR: blue">&lt;</SPAN><SPAN=20
style=3D"COLOR: maroon">ContactGroup</SPAN><SPAN style=3D"COLOR: =
fuchsia">=20
</SPAN><SPAN style=3D"COLOR: red">Number</SPAN><SPAN=20
style=3D"COLOR: blue">=3D"1"</SPAN><SPAN style=3D"COLOR: fuchsia"> =
</SPAN><SPAN=20
style=3D"COLOR: red">DisplayName</SPAN><SPAN=20
style=3D"COLOR: blue">=3D"~"&gt;<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
face=3DArial><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;</SPAN><SPAN=20
style=3D"COLOR: blue">&lt;/</SPAN><SPAN=20
style=3D"COLOR: maroon">ContactGroup</SPAN><SPAN=20
style=3D"COLOR: blue">&gt;<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT =
face=3DArial><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</=
SPAN></SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue">&lt;/</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: maroon">ContactGroups</SPAN><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue">&gt;</SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue"><FONT =
face=3DArial>........</FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue"><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue"><FONT face=3DArial><FONT =
color=3D#000000>When I=20
then use</FONT> </FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; COLOR: blue"><FONT=20
face=3DArial></FONT></SPAN>&nbsp;</P><SPAN style=3D"FONT-SIZE: 10pt; =
COLOR: blue">
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><SPAN=20
style=3D"mso-spacerun: yes"><FONT color=3D#000000><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Times New Roman'; =
mso-ansi-language: EN-GB; mso-fareast-font-family: 'Times New Roman'; =
mso-fareast-language: DE; mso-bidi-language: AR-SA">&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; Public</SPAN><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; =
mso-ansi-language: EN-GB; mso-fareast-font-family: 'Times New Roman'; =
mso-fareast-language: DE; mso-bidi-language: AR-SA">=20
xmlNsM <SPAN style=3D"COLOR: blue">As</SPAN> <SPAN style=3D"COLOR: =
blue">New</SPAN>=20
XmlNamespaceManager(xmlDoc.NameTable)</SPAN></FONT></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><SPAN=20
style=3D"mso-spacerun: yes"><FONT color=3D#000000><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; =
mso-ansi-language: EN-GB; mso-fareast-font-family: 'Times New Roman'; =
mso-fareast-language: DE; mso-bidi-language: =
AR-SA"></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</FONT></SPAN><SPAN style=3D"COLOR: blue">Dim</SPAN><FONT =
color=3D#000000> node=20
</FONT><SPAN style=3D"COLOR: blue">As</SPAN><FONT color=3D#000000>=20
XmlNode<o:p></o:p></FONT></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
color=3D#000000><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>xmlDoc.Load(pfad)<o:p></o:p></FONT></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN =
lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT =
color=3D#000000><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;</SPAN></FONT><SPAN=20
style=3D"COLOR: blue">Dim</SPAN><FONT color=3D#000000> nodeX =
</FONT><SPAN=20
style=3D"COLOR: blue">As</SPAN><FONT color=3D#000000> XmlNode =3D=20
xmlDoc.SelectSingleNode("/HomedResources", =
xmlNsM)<o:p></o:p></FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000></FONT>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000>The SelectSingleNode Method doesn't find any =
node!</FONT></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000></FONT>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000>But when I remove the xmlns-Attribute&nbsp;on the top of =
&nbsp;the=20
XML-Document SelectSingle Node find a node.</FONT></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000></FONT>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000>Any Idea how to use SelectSingleNode with =
Namespaces?</FONT></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000></FONT>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000>thanx</FONT></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000></FONT>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><FONT face=3DArial=20
color=3D#000000>Marcel</FONT></SPAN></P></DIV></BODY></HTML>

------=_NextPart_000_0006_01C54429.49A1B710--

0
4/18/2005 1:14:16 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
1201 Views

Similar Articles

[PageSpeed] 24

I haven't tried out the code but I have noticed that you didn't place the
namespace between quotes.

Gabriel Lozano-Mor�n

"Jonathan" <Jonathan@weissnichwo.com> wrote in message
news:#hVsAiBRFHA.244@TK2MSFTNGP12.phx.gbl...
Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources
xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">
        <HomedResource UserAtHost="PBoul@team.de" Enabled="1"
VersionPermission="10"
          VersionContact="25" DisplayName="Boullay, Peter"
Email="PBoul@team.de" Phone="+88
           09 75" LastRegisterTime="2005-03-29T09:36:00"
           xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">
               <ContactGroups>
                      <ContactGroup Number="1" DisplayName="~">
                      </ContactGroup>
               </ContactGroups>
.........

When I then use

        Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)
        Dim node As XmlNode
        xmlDoc.Load(pfad)
        Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/HomedResources",
xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of  the XML-Document
SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?

thanx

Marcel


0
4/18/2005 1:30:25 PM

Jonathan wrote:


> I use a XML-Doc with a Namespace like the following example:
>  
> 
> <HomedResources 
> xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">
> 
>         <HomedResource UserAtHost="PBoul@team.de" Enabled="1" 
> VersionPermission="10"   
> 
>           VersionContact="25" DisplayName="Boullay, Peter" 
> Email="PBoul@team.de" Phone="+88  
> 
>            09 75" LastRegisterTime="2005-03-29T09:36:00"
> 
>            xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">
> 
>                <ContactGroups>
> 
>                       <ContactGroup Number="1" DisplayName="~">
> 
>                       </ContactGroup>
> 
>                </ContactGroups>
> 
> ........
> 
>  
> 
> When I then use
> 
>  
> 
>         Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)
> 
>         Dim node As XmlNode
> 
>         xmlDoc.Load(pfad)
> 
>         Dim nodeX As XmlNode = 
> xmlDoc.SelectSingleNode("/HomedResources", xmlNsM)
> 
>  
> 
> The SelectSingleNode Method doesn't find any node!
> 
>  
> 
> But when I remove the xmlns-Attribute on the top of  the XML-Document 
> SelectSingle Node find a node.
> 
>  
> 
> Any Idea how to use SelectSingleNode with Namespaces?

Within XPath 1.0 you always need to bind a prefix to a namespace URI to 
select elements in a certain namespace:
   <http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
4/18/2005 1:46:34 PM
You need to have a "dummy" prefix associated with that namespace.
xmlNsM.AddNamespace("default", 
"http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp");

Then use that prefix with your XPath queries:
Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/default:HomedResources", 
xmlNsM)

PS
"default" is just a name, it could have been anything.

-- 
Regards,
Dennis JD Myr�n
Oslo Kodebureau
"Jonathan" <Jonathan@weissnichwo.com> wrote in message 
news:%23hVsAiBRFHA.244@TK2MSFTNGP12.phx.gbl...
Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources 
xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">
        <HomedResource UserAtHost="PBoul@team.de" Enabled="1" 
VersionPermission="10"
          VersionContact="25" DisplayName="Boullay, Peter" 
Email="PBoul@team.de" Phone="+88
           09 75" LastRegisterTime="2005-03-29T09:36:00"
           xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">
               <ContactGroups>
                      <ContactGroup Number="1" DisplayName="~">
                      </ContactGroup>
               </ContactGroups>
.........

When I then use

        Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)
        Dim node As XmlNode
        xmlDoc.Load(pfad)
        Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/HomedResources", 
xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of  the XML-Document 
SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?

thanx

Marcel 


0
dennis5359 (37)
4/18/2005 1:48:03 PM
Reply:

Similar Artilces:

Namespace Prefixes
Hi, i have a SOAP XML which is similar to this: <request xmlns="http://www.someurl.com"> <abc> <xyz></xyz> <xyz></xyz> </abc> I need the same namespace for 'request' and 'abc' but i want to maintain the default namespace for 'xyz'. i.e, i want the xml to look something like this: <prefix:request xmlns:prefix="http://www.someurl.com"> <prefix:abc> <xyz></xyz> // These do NOT come under 'prefix'. <xyz></xyz> // They are xmlns = "&quo...

The correct way to set XSD namespaces?
Hi, I have created a set of schemas for messages that i need to exchange between services. I set the targetNamespace ="http://mycompany/services/abc" and the root elements have names like FindCustomerRequest, FindCustomerResponse, CreateCustomerRequest and so on. In Biztalk when a message of any of the above comes in, it validates correctly because the engine sets the subscription to "http://mycompany/services/abc#FindCustomerRequest" . I also managed to create a webservice with these XSDs. However when creating a proxy i got an error saying that the targetNamespa...

XPath expression with namespace
Hello I am trying to use SelectSingleNode in an XMLDocument for a node that has namespace defined. My problem is the XPath for the node with no namespace defined works as soon as I put namespace it returns nothing. Help KB Can you post your sample so we can take a look at it? Thanks, Hoang Nguyen -- This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm Note: For the benefit of the community-at-large, all responses to this message are best d...

SelectSingleNode question
This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C4D0E5.4D4014F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am somewhat new to extracting data from an XML document in .Net. My document looks like this: <?xml version=3D"1.0" encoding=3D"UTF-8"?> <RMA-Standard> <IncomeData> <NetSales>64000000</NetSales> <COGS>80.0</COGS> <ProfitBeforeTax>6.0</ProfitBeforeTax> </IncomeData> </RMA-Standard> I tried to do the followin...

namespace of AfxLoadLibrary
Hi, I did not find in which namespace is define AfxLoadLibrary(). I'm migrating my app under .NET and as i did not find something useful in .NET (event if DllimportAttribute exists), i would like to mix MFC and .NET in a class. thanks a lot, Alain "--== Alain ==--" <nospam@noemail.com> wrote in message news:uoWGEF67GHA.3340@TK2MSFTNGP04.phx.gbl... > Hi, > > I did not find in which namespace is define AfxLoadLibrary(). This is a MFC method and this does not have a namespace as .Net does or perhpas its what you may call a global namespace. You should be able ...

missing namespace on root element of WCF proxy client
Hi, I have the following class that is exposed as a webservice method parameter parameter . [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:schemas.sequel.com/ genericImport")] [System.Xml.Serialization.XmlRootAttribute(Namespace="urn:schemas.sequel.com/ genericImport", IsNullable=false)] public partial class Schema { private Import importField; /// <remarks/> public Import Import { get { return this.importField; } set { this.importField = value; ...

XML selectsinglenode
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML http://GreenJAR/DAVCatalog/Dashboards/GreenJAR/Documents/Schemas/RiXML2.xsd" researchID="" createDateTime="2003-07-10T00:00:00" language="eng" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.rixml.org/2002/6/RIXML"> <Product productID="BJZABULLETIN_0711" eventIndicator="No" sequence="0"> <StatusInfo sta...

Apparent documentation contradiction for XmlNode.SelectSingleNode(
I just noticed something confusing the MSDN documentation for the XmlNode.SelectSingleNode() function here http://msdn2.microsoft.com/en-us/library/fb63z0tw.aspx It says, under the "Return Value" section that "The XmlNode should not be expected to be connected "live" to the XML document." but in the sample code modifies the node returned from the function and then prints the entire document. Did I mis-interpret the description of the return value or is the sample wrong? I've done this before and it's always worked AFAIK. SailBoffin wrote: &g...

XslTransform not excluding default namespace despite exclude-result-prefixes attribute?
I'm writing an xslt in vs.net 2003 and in order to get intellisense on the html content I added the default namespace declaration xmlns="http://schemas.microsoft.com/intellisense/ie5". However, even though I also have exclude-result-prefixes="#default" declared the default namespace is still outputted on the resulting document. <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.microsoft.com/intellisense/ie5" xmlns:...

XPath + SelectSingleNode
Hi All, I have this weird problem. I have an xml document and tried to do an XPath query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method. Is this a known problem with XPath and SelectSingleNode? Code snippet: <snip> XmlDocument xml= new XmlDocument(); xml.LoadXml(xmlString); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xml.NameTable); namespaceManager.AddNamespace("defns", defns); // return xml.DocumentElement.SelectSingleNode(xpath, namespaceManager); <-- does not work return xml.DocumentEl...

Namespace issues.
We have a XML script which uses the default namespace. See below: <?xml version="1.0" encoding="UTF-16"?> <Import xmlns="http://www.blah.com/nVanta" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blah.com/BlahBlah.xsd"> .... Then we try to read the nodes from the XML file using following code ( simplified for clarity) : public IXmlMapperNavigator Read(string xPath ) { XmlMapperNavigator map = null; // Optimize the ...

SelectSingleNode problem
Hi! The input xml file: <?xml version="1.0" encoding="utf-8" ?> <!-- Konfigur�ci� le�r�sa --> <Konfig xmlns:bk="urn:inifile"> <Konfiguracio> <szerver neve = "A1"></szerver> </Konfiguracio> </Konfig> XmlDocument xd = new XmlDocument(); xd.Load(Application.StartupPath + "\\Server.xml"); //Create an XmlNamespaceManager for resolving namespaces. XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable); nsmgr.AddNamespace("bk", "urn:inifile"); string xp = &quo...

Headache with namespaces ...
Hi I am having trouble with namespaces: Using the .NET System.XML classes, whenever I run an xpath on a file with a namespace, the xpath query returns nothing, but when I remove the namespace from the xml file I am quering, the xpath query works. I am trying to run a SelectSingleNode(xpath) function on an XmlNode, but when the source xml file has a default namespace, for example: "xmlns="urn:blah-org:v3" in the root node, then the SelectSingleNode function does not return anything. When I remove the default namespace from the source xml file, the the SelectSingleNode(...

The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared Error
I get the following error when I try to validate XML against a schema: The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared My questions are: 1. Why I am I getting this error? 2. How can I resolve? I got the schema definition from a third party (ACORD). I tried to do this using two different methods: Method 1 =96 Using a LINQ XDoc (preferred way) Private Function ValidXsd(ByVal AcordXml As String) As Boolean Dim schemas As New XmlSchemaSet() Dim returnVal As Boolean schemas.Add(Nothing, XmlReader.Create(Server.MapPath("Includes \acord-pcs-v1...

SelectSingleNode..Not Working..???
Hi, I have an Xml file in which i am storing the usernames and password and some other user details. The file contains data as shown below.. <?xml version="1.0" encoding="utf-8"?> <RoleTables xmlns="http://tempuri.org/UserPass.xsd"> <Table> <username>Arun</username> <password>jgEEnsYs+ZY=</password> <Email>arun@yahoo.com</Email> </Table> <Table> <username>sweta</username> <password>A/JvqRbKGes=</password> <Email>sita@ere.com</Email&...

SelectSingleNode with XmlDataDocument
I have code that worked with an XMLDocument. Now I'm trying to convert it to use with a synchronized XML dataset loaded from my database. The only difference I can see is that the DataDocument constructer has added an xmlns attribute to the parent tag I find that xDoc.GetElementsByTagName works fine, but xDoc.SelectSingleNode and xDoc.SelectNodes both return Nothing, even when there are clearly child nodes matching the request. The XML was created from a loaded dataset with nested relations. Here is my code. xNode is Nothing after the SelectSingleNode statement Any help will be appreci...

XmlSerializerNamespaces moves namespace to root node
This problem should be easily reproducable if anybody has the time. I need to build the following XML programatically and decided to use the XMLSerializer. I simplified the XML (myExample.xml) that i need to create for this post. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <m:TopElm xmlns:m="myNameSpace"> <Elm1>H...

assign dt as namespace for xmlelement
I am trying to duplicate an xml document, and I am pretty new to xml. I am using hte Xml namespace and taking advantage of the xmldocument class. I would like to add the following to an element xmlns:dt="urn:schemas-microsoft-com:datatypes" Is there a way to do this through the setattribute or createelement methods? Whenever I try all i get is the xmlns="urn:schemas-microsoft-com:datatypes" -------------------------------- From: Matt Torline ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>X8iAJQuYZEulcatGDsqe+w==</Id&...

Namespace Question
I sent this question in before, so apologies. I have a number of schemas which I add into a schema collection. A number of the schemas define types, the others contain business context message details (e.g. updating an employee etc). The schemas which define general types have their own namespace defined. All the other schemas have the >>same<< namespace. After loading 101 schemas into my collection I get the error "Server was unable to process request. The global element urn:xxxx/yyy/zzz:abc has already been declared" There are still approximately 140 schemas in tota...

SelectSingleNode with namespaces
My question is somewhat related to the previous question in this newsgroup: http://groups.google.de/group/microsoft.public.dotnet.xml/browse_frm/thread/db094f140f8359ca/5d58771b3b60cd47?hl=de#5d58771b3b60cd47 I am having trouble unerstanding how to use XmlNode.SelectSingleNode Method (String, XmlNamespaceManager) node when an xmlns Atrribute is present. this is my xml file: <?xml version="1.0" encoding="utf-8" ?> <configuration xmlns="http://company.de/VCT9/Core/Configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quo...

Referencing Additional Namespaces XSL
I need to use a string replace function in my XSL document. I found a W3 library that has numerous string functions such as fn:replace(). When I try using the namespace, I get an error "Cannot find the script or external object that implements prefix 'http://www.w3.org/2005/02/xpath-functions'. I am using VB, an XMLDocument object, an XSLCompiledTransform object, and an XmlTextWriter to store the transformation. Here is the start of my XSL document: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl=...

performance problem with SelectSingleNode
I have an application written in C# and i am using MS XML DOM! I have a document with the following structure (only the <DicEntry> - Elements are important): <NewDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"> . <DicEntry TextKey="Test1" KeyDependency="True"> <default>Test1</default> <de>Button Germanmanuell</de> <it /> </DicEntry> <DicEntry TextKey="Dialog1" KeyDependency="True"> <default>Dialog1</default> <de /> &...

SelectSingleNode fails
I'm trying to get the value of a single node using SelectSingleNode and I get the NullReference Error. Example: I want to get the URL in the HTML element but the GetHTMLPath() function fails on the objNode line. Any ideas how to make this work? You'll see I've tried different methods of getting the values. XML 4.0 was so easy. I'm using VB.Net 2003 on XP Pro. Thanks, King Wilder =============================================== <?xml version="1.0"?> <Root xmlns="http://myuri.org/myschema.xsd"> <Settings> <Paths> ...

using namespace in xpath for SelectSingleNode
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have to state a namespace in the xpath. Can the node be accessible by the xpath specified? Thanks. XmlDocument xmldoc = new XmlDocument(); XmlCDataSection cdata = xmldoc.CreateCDataSection(requestString); String soapEnvelope = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://wwww3.org/1999/XMLSchema-instance\...

SelectSingleNode Error
I'm getting the following error: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function. On the following line of code: XmlNode sNode = styleDoc.DocumentElement.SelectSingleNode (@"//xsl:stylesheet//xsl:template[@match='custID']/span"); What can I do to resolve it? Demetri wrote: > I'm getting the following error: > > Namespace Manager or XsltContext needed. This query has a > prefix, variable, or user-defined function. > > On the following line of code: > > XmlNode sNode = styleDoc.D...