#利用XmlTextReader读取XML节点数据
xml内容:
<?xml version="1.0" encoding="utf-8" ?>
<google>
<googleColorBorder>f6fbff</googleColorBorder>
<googleColorBG>f6fbff</googleColorBG>
<googleColorLink>666666</googleColorLink>
<googleColorText>046b7A</googleColorText>
<googleColorUrl>008000</googleColorUrl>
</google>
cs代码:
protected void Page_Load(object sender, EventArgs e)
{
XmlTextReader xtr = new XmlTextReader("c:\\AdColor2.xml");
while (xtr.Read()) {
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorBorder") {
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorBG")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorLink")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorText")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorUrl")
{
Response.Write(xtr.ReadString() + "<br/>");
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<google>
<googleColorBorder>f6fbff</googleColorBorder>
<googleColorBG>f6fbff</googleColorBG>
<googleColorLink>666666</googleColorLink>
<googleColorText>046b7A</googleColorText>
<googleColorUrl>008000</googleColorUrl>
</google>
cs代码:
protected void Page_Load(object sender, EventArgs e)
{
XmlTextReader xtr = new XmlTextReader("c:\\AdColor2.xml");
while (xtr.Read()) {
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorBorder") {
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorBG")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorLink")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorText")
{
Response.Write(xtr.ReadString() + "<br/>");
}
if (xtr.NodeType == XmlNodeType.Element && xtr.LocalName == "googleColorUrl")
{
Response.Write(xtr.ReadString() + "<br/>");
}
}
}