Possible bug in XmlNode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Mon

    #1

    Possible bug in XmlNode

    I have a XML document with elements like
    <offer>
    <field name="name"><![CDATA[DS SIL CON]]></field>
    <field name="merchant_ id"><![CDATA[3001]]></field>
    .....
    </offer>

    I know not the best XML! Now I am selecting different values by XPath
    having an XmlNode representing the <offer> element. Now when I try something
    like this

    XmlNode dataNode = offerNode.Selec tSingleNode("fi eld[@name='merchant _id']");

    this works fine and returns a result. However the following query runs but
    returns nothing:

    XmlNode dataNode = offerNode.Selec tSingleNode("fi eld[@name='name']");

    Now the only thing I can think of is that the attribute and text have the
    same value. I tried the same query as an XPathExpression :

    XPathExpression searchData = navigator.Compi le(("field[@name='name']");
    XPathNodeIterat or iter = navigator.Selec t(searchData);

    and surprise surprise it works.
    So is this a bug in using the SelectNodes() or SelectSingleNod e methods on
    an XmlNode?
  • Martin Honnen

    #2
    Re: Possible bug in XmlNode



    J Mon wrote:[color=blue]
    > I have a XML document with elements like
    > <offer>
    > <field name="name"><![CDATA[DS SIL CON]]></field>
    > <field name="merchant_ id"><![CDATA[3001]]></field>
    > ....
    > </offer>[/color]
    [color=blue]
    > However the following query runs but
    > returns nothing:
    >
    > XmlNode dataNode = offerNode.Selec tSingleNode("fi eld[@name='name']");[/color]

    This is a complete test case using your example XML and your example
    XPath expression:

    using System;
    using System.Xml;

    public class Test2005091901 {
    public static void Main (string[] args) {
    string xmlSource = @"<offer>
    <field name=""name"">< ![CDATA[DS SIL CON]]></field>
    <field name=""merchant _id""><![CDATA[3001]]></field>
    </offer>";

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.Loa dXml(xmlSource) ;

    XmlElement offerElement = xmlDocument.Doc umentElement;

    XmlNode field = offerElement.Se lectSingleNode( "field[@name='name']");

    Console.WriteLi ne("SelectSingl eNode result: {0}.", field);
    }
    }

    I get the output

    SelectSingleNod e result: System.Xml.XmlE lement.

    with .NET 1.1 which seems fine to me, an element node is found.

    Does that test case give a different result for you?



    --

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

    Comment

    • J Mon

      #3
      Re: Possible bug in XmlNode

      I stand corrected. Must be something deeper nested in the code that is
      causing the XmlNode to be empty.

      "Martin Honnen" wrote:
      [color=blue]
      >
      >
      > J Mon wrote:[color=green]
      > > I have a XML document with elements like
      > > <offer>
      > > <field name="name"><![CDATA[DS SIL CON]]></field>
      > > <field name="merchant_ id"><![CDATA[3001]]></field>
      > > ....
      > > </offer>[/color]
      >[color=green]
      > > However the following query runs but
      > > returns nothing:
      > >
      > > XmlNode dataNode = offerNode.Selec tSingleNode("fi eld[@name='name']");[/color]
      >
      > This is a complete test case using your example XML and your example
      > XPath expression:
      >
      > using System;
      > using System.Xml;
      >
      > public class Test2005091901 {
      > public static void Main (string[] args) {
      > string xmlSource = @"<offer>
      > <field name=""name"">< ![CDATA[DS SIL CON]]></field>
      > <field name=""merchant _id""><![CDATA[3001]]></field>
      > </offer>";
      >
      > XmlDocument xmlDocument = new XmlDocument();
      > xmlDocument.Loa dXml(xmlSource) ;
      >
      > XmlElement offerElement = xmlDocument.Doc umentElement;
      >
      > XmlNode field = offerElement.Se lectSingleNode( "field[@name='name']");
      >
      > Console.WriteLi ne("SelectSingl eNode result: {0}.", field);
      > }
      > }
      >
      > I get the output
      >
      > SelectSingleNod e result: System.Xml.XmlE lement.
      >
      > with .NET 1.1 which seems fine to me, an element node is found.
      >
      > Does that test case give a different result for you?
      >
      >
      >
      > --
      >
      > Martin Honnen --- MVP XML
      > http://JavaScript.FAQTs.com/
      >[/color]

      Comment

      Working...