我有一個大的XMLTEXTREADER讀取我正在讀取。循環訪問xml元素問題
這裏是我的代碼
while (reads.Read())
{
switch (reads.NodeType)
{
case XmlNodeType.Element:
{
if (reads.Name == "TITLE")
{
Response.Write("<Br />");
Intel = reads.ReadInnerXml();
}
Response.Write(Intel);
Intel = "";
}
break;
}
}
這適用於在文檔打印的所有標籤大。現在我有一個名爲Authors的標籤,對於某些Books,有多個Author。
所以我的XML看起來像下面
<set1>
<title>Test </Title>
<intel_auth id="9">
<fname>ABC</fname>
<mname>M.</mname>
<lname>app</lname>
</intel_auth>
<intel_auth id="130">
<fname>Brad</fname>
<lname>e</lname>
</intel_auth_auth>
<intel_auth id="31">
<fname>Robin</fname>
<lname>neil</lname>
</intel_auth>
<intel_auth id="232">
<fname>Mason</fname>
<lname>Rodriguez</lname>
</intel_auth>
</set1>
我擁有多套並打印所有的標題和不打印旁邊作者姓名。
我用下面的代碼
case XmlNodeType.Element:
{
//string strURI = reads.NamespaceURI;
//string name = reads.Name;
string Authors = "";
if (reads.Name == "TITLE")
{
Response.Write("<Br />");
Intel = reads.ReadInnerXml();
if (reads.Name == "FNAME")
{
Authors += reads.Value;
}
if (reads.Name == "MNAME")
{
Authors += reads.Value;
}
if (reads.Name == "LNAME")
{
Authors += reads.Value;
}
}
Response.Write(Intel+Authors);
Intel = "";
Authors = "";
}
break;