<name>Tag 6</name>
using XmlTextReader how can i re开发者_如何学编程ad the value of the text between the name tag .ie how can i get Tag 6
With ReadElementString function:
var text = string.Empty;
using (var reader = new XmlTextReader(filename))
{
reader.MoveToContent();
text = reader.ReadElementString(); // read content text from current node
reader.Close();
}
From the docs I'm guessing you need to do something like
ReadToDescendant http://msdn.microsoft.com/en-us/library/ayf5ffy5.aspx
to find the name node.
then
ReadInnerXml to get the content.
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readinnerxml.aspx
not used it though
while (reader.Read()){
if(reader.NodeType == XmlNodeType.Element && reader.Name == "name"){
this.tagXml.Append("<").Append(reader.Name).Append(">");
currentTag = reader.Name.Trim();
//first loop go through this
}
if(reader.NodeType== XmlNodeType.Text){
//second loop go through this
if (currentTag == "name"){
this.tagXml.Append(reader.Value);
}
}
}
精彩评论