I am reading in data from an external server. The data comes in fine and I can set all the text values but when I try to read in tagname there it doesn't work. My overall goal is to populate a dataGridView with tag names in one column and tag values in another. To reiterate I have the tag value but not the tag name. The problem code:
if (xmlRead.NodeType == XmlNodeType.Text){
Console.WriteLine(xmlRead.Name + " : " + xmlRead.Value);
}
where xmlRead is my XmlReader.
The result is : Beef
Example data format is
<type>Beef</type>
Say you had an XML structured like:
<element>Some Text</element>
First an XmlReader would first hit a node with type XmlNodeType.Element the name element, and an empty Value.
Then it would hit a node with type XmlNodeType.Text, no name, and the value "Some Text".
Then it would hit a node with the type XmlNodeType.EndElement, the name element and an empty Value.
You're trying to get the name at the point where there is none. Either get the name when you read the element and then later read the text node, or perhaps upon reading the element, and getting its name then immediately call ReadElementContentAsString() to get the contents of inner text node(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With