Newbie question - XML SOAP

This is a discussion on Newbie question - XML SOAP ; I have this XML <?xml version="1.0" encoding="utf-8"?> <PORMessage key="new" j:effectiveDate="2007-05-21" xmlns:j="http://www.xxx.com/xxxx/3.0.3" xmlns="http://www.xxx.com"> <ActivityID> <ID>12345</ID> </ActivityID> </PORMessage> =================== END ===== Then my C# code is: xmlDoc.LoadXml(xmlMsg); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3"); XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr); Question: porNode always ...

+ Reply to Thread
Results 1 to 3 of 3

Newbie question

  1. Default Newbie question

    I have this XML

    <?xml version="1.0" encoding="utf-8"?>
    <PORMessage key="new" j:effectiveDate="2007-05-21"
    xmlns:j="http://www.xxx.com/xxxx/3.0.3"
    xmlns="http://www.xxx.com">
    <ActivityID>
    <ID>12345</ID>
    </ActivityID>
    </PORMessage>

    =================== END =====

    Then my C# code is:

    xmlDoc.LoadXml(xmlMsg);
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3");

    XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr);

    Question: porNode always return null. I have some similar program that
    works. I don't know why this one does not. If I take out the 3rd line on the
    xml, it return the right node.

    How do I make it work and an explanation would be appreciated. Thanks



  2. Default Re: Newbie question

    Phil Hunt wrote:
    > I have this XML
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <PORMessage key="new" j:effectiveDate="2007-05-21"
    > xmlns:j="http://www.xxx.com/xxxx/3.0.3"
    > xmlns="http://www.xxx.com">
    > <ActivityID>
    > <ID>12345</ID>
    > </ActivityID>
    > </PORMessage>
    >
    > =================== END =====
    >
    > Then my C# code is:
    >
    > xmlDoc.LoadXml(xmlMsg);
    > XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    > nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3");


    nsmgr.AddNamespace("df", "http://www.xxx.com/");

    > XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr);


    XmlNode porNode = xmlDoc.SelectSingleNode("//df:PORMessage", nsmgr);

    The default namespace declaration (xmlns="http://www.xxx.com/") means
    that the elements are in the namespace http://www.xxx.com/. With XPath
    1.0 to select elements in a namespace you need to bind a prefix (e.g.
    df) to the namespace URI and use the prefix to qualify element names in
    your XPath expression.


    --

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

  3. Default Re: Newbie question

    thanks. that's it.


    "Martin Honnen" <mahotrash@yahoo.de> wrote in message
    news:%23PEorA0NIHA.4272@TK2MSFTNGP06.phx.gbl...
    > Phil Hunt wrote:
    >> I have this XML
    >>
    >> <?xml version="1.0" encoding="utf-8"?>
    >> <PORMessage key="new" j:effectiveDate="2007-05-21"
    >> xmlns:j="http://www.xxx.com/xxxx/3.0.3"
    >> xmlns="http://www.xxx.com">
    >> <ActivityID>
    >> <ID>12345</ID>
    >> </ActivityID>
    >> </PORMessage>
    >>
    >> =================== END =====
    >>
    >> Then my C# code is:
    >>
    >> xmlDoc.LoadXml(xmlMsg);
    >> XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    >> nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3");

    >
    > nsmgr.AddNamespace("df", "http://www.xxx.com/");
    >
    >> XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr);

    >
    > XmlNode porNode = xmlDoc.SelectSingleNode("//df:PORMessage", nsmgr);
    >
    > The default namespace declaration (xmlns="http://www.xxx.com/") means that
    > the elements are in the namespace http://www.xxx.com/. With XPath 1.0 to
    > select elements in a namespace you need to bind a prefix (e.g. df) to the
    > namespace URI and use the prefix to qualify element names in your XPath
    > expression.
    >
    >
    > --
    >
    > Martin Honnen --- MVP XML
    > http://JavaScript.FAQTs.com/




+ Reply to Thread

Similar Threads

  1. newbie question
    By Application Development in forum Perl
    Replies: 3
    Last Post: 10-12-2007, 03:38 PM
  2. Newbie IDL question
    By Application Development in forum Idl-pvwave
    Replies: 5
    Last Post: 01-08-2007, 11:53 PM
  3. Newbie question...simple rule question...
    By Application Development in forum PROLOG
    Replies: 6
    Last Post: 08-12-2005, 05:33 AM
  4. Newbie question
    By Application Development in forum basic.visual
    Replies: 0
    Last Post: 11-29-2004, 11:50 AM
  5. Very [NEWBIE] question
    By Application Development in forum Graphics
    Replies: 8
    Last Post: 04-26-2004, 10:04 AM