Wednesday, December 1, 2010

How to Read Xml Document?

suppose we have a xml document books.xml...let us try to read that document...The books.xml looks like this...

Books.Xml





















Reading from the above xml document....


Output of the above Console Application is



Note: If the element has attributes...

Inspect the attributes. Element node types can include a list of attribute nodes that are associated with them. The MovetoNextAttribute method moves sequentially through each attribute in the element. Use the HasAttributes property to test whether the node has any attributes. The AttributeCount property returns the number of attributes for the current node.


//If the element has attributes like ...
Console.Write("<" + XmlRdr.Name);

while (XmlRdr.MoveToNextAttribute()) // Read the attributes.
Console.Write(" " + XmlRdr.Name + "='" + XmlRdr.Value + "'" +">");

break;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.