Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Is XPathNavigator.MoveToAttribute broken?

Back to Forum: Tech Off
  • User profile image
    z33driver

    I'm trying to use XPath to load an XML document.  I validate the document against a schema and then walk through the XML building an object model.

    I am having trouble with XPathNavigator.MoveToAttribute.  I have an element that has 2 attributes, Id and Seq.  Id is a string value and Seq is an integer value.

    XPathNavigator.MoveToAttribute("Id","");  works, and I can get the value, but when I then to XPathNavigator.MoveToAttribute("Seq","") it does not work.

    Any ideas?

  • User profile image
    z33driver

    If I do a .MoveToParent() after reading the first attribute and then .MoveToAttribute() it seems to work, but doesn't this defeat the purpose of using an XPathNavigator to walk through the Xml, since it has to jump to the beginning of the node each time?  Is this a bug or am I doing something wrong?

  • User profile image
    z33driver

    Anyone know anything about this?  Should you have to do a MoveToParent() by design, is it a bug, is there a better way to be reading through attributes (that may or may not be present as some are optional)?

  • User profile image
    Harlequin

    Maybe you can loop through the attributes, and add a switch on the name of the attribute...or something Smiley

    Here's a loop snippet from some code I have looping through attributes:

    if (MyXmlTextReader.HasAttributes && MyXmlTextReader.NodeType == XmlNodeType.Element)
    {

     for(int i = 0; i < MyXmlTextReader.AttributeCount; i++)
     {

      MyXmlTextReader.MoveToAttribute(i);
      Controls.Add(new LiteralControl(" " + MyXmlTextReader.Name + "=\"" + MyXmlTextReader.Value + "\""));
     }

     MyXmlTextReader.MoveToElement();

    }

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.