Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
| Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2007, 03:16 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default SelectSingleNode throwing exception:

Hi,

I have following XML which I need to modify and invoke a http request
I need to select a node but I am getting "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." Error
I am trying to access the <CUSTOMER/> tag with following code:


requestXmlDocument.SelectSingleNode("/SOAP-ENV:Envelope/SOAP-ENV:Body/m:MT_MaterialSearchRequest/" + XmlNodeName.CUSTOMER).InnerText
                        = some value;

Please consider following tags before giving answer:
• <SOAP-ENV:Envelope
• <SOAP-ENV:Body
• <m:MT_MaterialSearchRequest


Following is the Xml:

<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:MT_MaterialSearchRequest xmlns:m="http://br.eu/tl/v2">
      <CUSTOMER/>
      <SALES_ORG/>
      <DISTR_CHAN/>
      <DIVISION/>
      <SEARCH_RESULT_SIZE/>
      <DEFAULT_SORTING/>
      <RESULT_TYPE>R</RESULT_TYPE>
      <REQ_DATE/>
      <REQ_QTY/>
      <SALES_UNIT/>
      <SEARCH_PARAM_IN>
        <AGG_SEARCH/>
        <COMMERCIAL_CODE/>
        <DESCRIPTION/>
        <WIDTH/>
        <SERIE/>
        <RIM/>
        <LOAD_INDEX/>
        <SPEED_SYMBOL/>
        <PATTERN/>
        <TUBE_TYPE/>
        <BRAND/>
        <HIERARCHY/>
      </SEARCH_PARAM_IN>
      <VISIBILITY_ITEM_IN>
        <ITEM>
          <ITM_NUMBER/>
          <MATERIAL idtype=""/>
          <REQ_QTY/>
          <SALES_UNIT/>
          <REQ_DATE/>
        </ITEM>
      </VISIBILITY_ITEM_IN>
    </m:MT_MaterialSearchRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


I think I have to use XmlNamespaceManager, but I am not getting how do I use it in this case when there are following three tags in the xmldocument.
• <SOAP-ENV:Envelope
• <SOAP-ENV:Body
• <m:MT_MaterialSearchRequest



Thanks in advance,
Anup



--Everything you can imagine is real.--
__________________
--Everything you can imagine is real.--
 
Old February 3rd, 2008, 12:04 PM
Registered User
 
Join Date: Feb 2008
Location: Huntsville, Alabama, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The easiest and fastest way around this is just to use this for your XPath expression: "//CUSTOMER".

Otherwise you would have to do something like this (and this is off the top of my head, so if it doesn't compile don't get bent out of shape):

Dim xmlDoc As New System.Xml.XmlDocument()

Dim xmlNsm As New System.Xml.XmlNamespaceManager(xmlDoc.NameTable)
xmlNsm.AddNamespace("m", "http://br.eu/tl/v2");
' And so forth and so on
' ...
xmlDoc.SelectSingleNode("your XPath here")

The choice is your's, but simple, especially in this case, is better to me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXML selectSingleNode for XPath with quotation Vx XML 2 March 20th, 2007 11:44 AM
SelectNodes, SelectSingleNode weirdness dantell BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 October 19th, 2006 12:39 PM
C# XML--SelectSingleNode/SelectNodes is failing. gijomk C# 1 August 29th, 2006 09:48 AM
Axis client throwing exception sometimes chandootechie J2EE 0 March 17th, 2006 07:51 AM
RangeValidaor throwing exception anup_daware .NET Framework 1.x 0 March 16th, 2006 07:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.