System.Xml.XmlDocument   SelectSingleNode

pipe
pipe used Ask the Experts™
on
hi:

i have some xsl loaded into an xml.XmlDocument. i am trying to select
a parameter once it is loaded, however i recieve the following error:


{"Namespace Manager or XsltContext needed. This query has prefix or variable or userdefined function." }
    [System.Xml.XPath.XPathException]: {System.Xml.XPath.XPathException}
    System.Object: {System.Xml.XPath.XPathException}
    _COMPlusExceptionCode: 0xe0434f4d
    _className: null
    _exceptionMethod: null
    _exceptionMethodString: null
    _message: "System error."
    _innerException: null
    _helpURL: null
    _stackTrace: {System.Array}
    _stackTraceString: null
    _remoteStackTraceString: null
    _remoteStackIndex: 0x0
    _HResult: 0x80131943
    _source: null
    _xptrs: 0x0
    _xcode: 0xe0434f4d
    Message: "Namespace Manager or XsltContext needed. This query has prefix or variable or userdefined function."
    InnerException: null
    TargetSite: {System.Reflection.RuntimeMethodInfo}
    StackTrace: "   at System.Xml.XPath.CompiledXpathExpr.get_QueryTree()
   at System.Xml.XPath.XPathSelectionIterator..ctor(XPathNavigator nav, XPathExpression expr)
   at System.Xml.XPath.XPathNavigator.Select(String xpath)
   at System.Xml.XmlNode.SelectNodes(String xpath)
   at System.Xml.XmlNode.SelectSingleNode(String xpath)
   at WebMail.WebMailViewer.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webmail\webmailviewer.aspx.cs:line 58"
    HelpLink: ""
    Source: "System.Xml"
    HResult: 0x80131943




[C# CODE]

System.Xml.XmlDocument xsl = new System.Xml.XmlDocument();    
xsl.Load(Server.MapPath("WebMailViewer.xsl"));
System.Xml.XmlNode n = xsl.DocumentElement.SelectSingleNode("//xsl:param[@name='MessageID']");





[XSL DOCUMENT]

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="MessageID"/>
     <xsl:template match="/">
          <html>
               <head>
                    <title>WebMail</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
               </head>
               <body>          
               </body>
          </html>
     </xsl:template>
         
</xsl:stylesheet>


thanks: js
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Did you try of using XPathDocument and XPathNavigator classes for getting your node?

Perhaps they can help...I saw something about the namespacing..

Mario
Have a look at XmlNamespaceManager class. You have the second parameter of this type in declaration of:

public XmlNode SelectSingleNode(string, XmlNamespaceManager);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial