tags是什么意思:Easily find tags and values in a large xml document using XmlTextReader in c#

Use XmlTextReader to parse large XML documents.

public void findAParticularNodesUsingTextReader()

{

XmlTextReader txtreaderObj = new XmlTextReader(@"C:\

Document and Settings\ Administrator\Desktop\samleXmlDoc.xml");

txtreaderObj.WhitespaceHandling = WhitespaceHandling.None;

while (txtreaderObj.Read())

{

if (txtreaderObj.Name.Equals("TotalPrice") &&

txtreaderObj.IsStartElement())

{

txtreaderObj.Read();

richTextBox1.AppendText(txtreaderObj.Value);

}

}

}

Result

12.36 11.99 7.97

Faster,read-only XPath query-based access to data,use XPathDocument and XPathNavigator along with xpath query.

public void FindTagsUsingXPthNaviatorAndXPathDocumentNew()

{

XPathDocument xpDoc = new XPathDocument(@"C:\Documents

andSettings\ Administrator\Desktop\samleXmlDoc.xml");

XPathNavigator xpNav = xpDoc.CreateNavigator();

XPathExpression xpExpression =

xpNav.Compile(@"/Orders/Order/TotalPrice");

XPathNodeIterator xpIter = xpNav.Select(xpExpression);

while (xpIter.MoveNext())

{

richTextBox1.AppendText(xpIter.Current.Value);

}

}

Result

12.36 11.99 7.97

Combining XmlReader and XmlDocument. _disibledevent="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">Minimize output size. More importantly, minimize input.

Tags:  tags是什么 strutstags striptags tags是什么意思

延伸阅读

最新评论

发表评论