SelectSingleNode Issue

  • Thread starter Bob Mixon [SPS MVP]
  • Start date
B

Bob Mixon [SPS MVP]

All,

There are so many newsgroups these days, I am not sure if this is the correct
one I should be posting to; if not, I apoligize!

I have the following xml file, this was generated by the .NET disco.exe utility.

<?xml version="1.0" encoding="utf-8"?>
<discovery xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.xmlsoap.org/disco/">
<contractRef ref="http://sps2003:81/Services/AdGroupsList/AdGroupsList.asmx?wsdl"
docRef="http://sps2003:81/Services/AdGroupsList/AdGroupsList.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/"
/>
<soap address="http://sps2003:81/Services/AdGroupsList/AdGroupsList.asmx"
xmlns:q1="http://tempuri.org/" binding="q1:AdGroupsListSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/"
/>
</discovery>

I am having a difficult time setting up the NamespaceManager and making the
SelectSingleNode call correctly to return the <contractRef> element. Can
someone please provide me with an example? Here is what I have so far:

XmlNamespaceManager nm = new XmlNamespaceManager( doc.NameTable );
nm.AddNamespace( "xsd", "http://www.w3.org/2001/XMLSchema" );
nm.AddNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
XmlElement discoveryElem = doc.DocumentElement;
XmlNode node = discoveryElem.SelectSingleNode( "//contractRef", nm );

The node variable always returns null.

Thank you in advance for all of the help!



----------------------------------------------------------
Bob Mixon
Managing Director
ShareSquared, Inc. - Your Knowledge Management Experts!
http://www.ShareSquared.com

Microsoft SharePoint Portal Server MVP
(Blog) http://bobmixon.xwiki.com
----------------------------------------------------------
 
J

Jon Skeet [C# MVP]

I am having a difficult time setting up the NamespaceManager and making the
SelectSingleNode call correctly to return the <contractRef> element. Can
someone please provide me with an example? Here is what I have so far:

XmlNamespaceManager nm = new XmlNamespaceManager( doc.NameTable );
nm.AddNamespace( "xsd", "http://www.w3.org/2001/XMLSchema" );
nm.AddNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
XmlElement discoveryElem = doc.DocumentElement;
XmlNode node = discoveryElem.SelectSingleNode( "//contractRef", nm );

The node variable always returns null.

Thank you in advance for all of the help!

You need the namespace for the contractRef element:

nm.AddNamespace( "scl", "http://schemas.xmlsoap.org/disco/scl/");
....
XmlNode node = discoveryElem.SelectSingleNode("//scl:contractRef", nm);
 
B

Bob Mixon [SPS MVP]

Thank you Jon, I really appreciate it!

----------------------------------------------------------
Bob Mixon
Managing Director
ShareSquared, Inc. - Your Knowledge Management Experts!
http://www.ShareSquared.com

Microsoft SharePoint Portal Server MVP
(Blog) http://bobmixon.xwiki.com
----------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top