【发布时间】:2009-04-24 07:53:27
【问题描述】:
我有一部分 XmlDocument Example.xml,如下所示:
<rapaine dotoc="palin" domap="rattmin">
<derif meet="local" />
<derif meet="intro" />
.
.
.
</rapaine>
在这里,我正在创建一个节点列表并获取元素 raplin 以获取其属性。
现在我想确定属性 'dotoc' 和 'domap' 是否是 rapaine 的属性,其各自的值始终是固定的。然后只有我可以使用其属性 'meet' 访问 childNodes 'deriff'。这里的值只会改变。
我已经写了一部分代码没有编译错误但是在调试时我发现它没有进入for循环来检查它的属性和子节点。
XmlNodeList listOfSpineRootNodes = opfXmlDoc.GetElementsByTagName("rapine");
for (int x = 0; x < listOfSpineRootNodes.Count; x++)
{
XmlAttributeCollection spineAttributes = listOfSpineRootNodes[x].Attributes;
string id = spineAttributes[0].Value;
if (spineAttributes != null)
{
XmlNode attrToc = spineAttributes.GetNamedItem("dotoc");
XmlNode attrPageMap = spineAttributes.GetNamedItem("domap");
if (attrToc.Value == "palin" && attrPageMap.Value == "rattmine")
{
if (listOfSpineRootNodes != null)
{
foreach (XmlNode spineNodeRoot in listOfSpineRootNodes)
{
XmlNodeList listOfSpineItemNodes = spineNodeRoot.ChildNodes;
if (listOfSpineItemNodes != null)
{
foreach (XmlNode spineItemNode in listOfSpineItemNodes)
{
if (spineItemNode.NodeType == XmlNodeType.Element
&& spineItemNode.Name == "derif")
{
XmlAttributeCollection spineItemAttributes = spineItemNode.Attributes;
if (spineItemAttributes != null)
{
XmlNode attrIdRef = spineItemAttributes.GetNamedItem("meet");
if (attrIdRef != null)
{
spineListOfSmilFiles.Add(attrIdRef.Value);
}
}
}
}
}
}
}
}
}
你能告诉我哪里出错了吗.. 谢谢....
【问题讨论】:
标签: c# xml xmldocument