• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

我这个XML中的节点该如何读取?

ifeasy 2004-11-01 04:18:39
<master cd_count="1" cd_release_date="2000/01/08" media_id="671902" volume="1" title="Tseng Shu Ching Ching Hsuan Chi" ll_title="精選">
<product_code type="UPC">0724352848454</product_code>
<alternate_product_code type="Digital_ICPN">0724352848454</alternate_product_code>
<custom_field name="Total_Components">1</custom_field>
<custom_field name="Total_Tracks">16</custom_field>
<genre>Pop/Rock</genre>
<artist name="Tseng, Shu Ching" ll_name="曾淑琴" role="Artist" />
<custom_field name="TPM_Code">11</custom_field>
<custom_field name="Release_Type_Code">AL</custom_field>
<track ll_title="不再等待天堂" number="1" title="Bu Zai Deng Dai Tian Tang">
<artist name="Tseng, Shu Ching" ll_name="曾淑琴" role="Artist" />
<custom_field name="Duration">235</custom_field>
<custom_field name="TPM_Code">11</custom_field>
<custom_field name="P_Notice">Digital Remaster (p) 2003 The Copyright in this sound recording is owned by a unit of EMI Music.</custom_field>
<custom_field name="Repertoire_Owner">EMI (TAIWAN) LTD</custom_field>
<custom_field name="Component_Number">1</custom_field>
<custom_field name="Hidden_Track_Flag">N</custom_field>
</track>
<track ll_title="天堂" number="1" title="Bu Zai Deng Dai Tian Tang">
<artist name="Tseng, Shu Ching" ll_name="曾淑琴" role="Artist" />
<custom_field name="Duration">235</custom_field>
<custom_field name="TPM_Code">11</custom_field>
<custom_field name="P_Notice">Digital Remaster (p) 2003 The Copyright in this sound recording is owned by a unit of EMI Music.</custom_field>
<custom_field name="Repertoire_Owner">EMI (TAIWAN) LTD</custom_field>
<custom_field name="Component_Number">1</custom_field>
<custom_field name="Hidden_Track_Flag">N</custom_field>
</track>
<track .....>
</track>
</master>

想读"master"下面部分子节点,其中"track"不定多。
...全文
98 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
BearRui 2004-11-02
XmlDocument doc=new XmlDocument();
doc.Load("XmlFile");

一、:
XmlNode node=doc.SelectSingleNode("//master");
for(int i=0;i<node.Attributes.Count;i++)
Console.WriteLine(node.Attributes.Item(i).Value.ToString());

二、选择所有 name="Tseng, Shu Ching"的artist节点
XmlNodeList nodes=doc.SelectNodes("//artist[@name='Tseng, Shu Ching']");
回复
ifeasy 2004-11-02
想读取:一、<master cd_count="1" cd_release_date="2000/01/08" media_id="671902" volume="1" title="Tseng Shu Ching Ching Hsuan Chi" ll_title="精選"> 中的属性值:1,2000/01/08,671902,1,Tseng Shu Ching Ching Hsuan Chi,精選,<track>类似

二、<master>下的子节点,如:<product_code><alternate_product_code><custom_field>....
<track>下的子节点:〈artist〉〈custom_field〉
回复
BeginnerBBB 2004-11-01
XPathDocument xpathdoc = new XPathDocument(Server.MapPath(".")+"\\Config.config");
XPathNavigator xpathnavigator = xpathdoc.CreateNavigator();
// 选择符合条件的节点集
XPathNodeIterator xpathNi = xpathnavigator.Select("/master/track[@cd_count='1']");
while(xpathNi.MoveNext())
{
string str = xpathNi.Current.value;
}
回复
BearRui 2004-11-01
不知道楼主要读什么东西!!!
回复
zhouzh197895 2004-11-01
我不知道你想讀什么﹐讀track的屬性"cd_count=1"的﹐如下﹕
"master/track[@cd_count='1']"
回复
commars 2004-11-01
支持一下!
回复
ifeasy 2004-11-01
还想读,master及track 的属性,如:cd_count=“1”
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2004-11-01 04:18
社区公告

让您成为最强悍的C#开发者