根据 JNYRanger 的建议,我昨晚想出了这个:
TraverseNodes(xmlSbcCoreData.ChildNodes);
它传入我的 XmlDocument 对象...
private void TraverseNodes(XmlNodeList nodes) {
Boolean haveValue = false;
foreach (XmlNode node in nodes) {
// Do something with the node.
if (!node.Name.Equals("#text")) {
nodeName = node.Name;
capturedNode = node;
haveValue = false;
} else {
nodeValue = node.Value;
haveValue = true;
}
if (haveValue) {
Debug.WriteLine("-----------------------------------------------------");
Debug.WriteLine("GetRecursiveList - capturedNode: " + capturedNode.Name);
Debug.WriteLine("GetRecursiveList capturedNode Parent: " + capturedNode.ParentNode.Name);
Debug.WriteLine("GetRecursiveList NAME|VALUE: " + nodeName + " | " + nodeValue);
string path = getNodePath(capturedNode);
Debug.WriteLine("GetRecursiveList capturedNode PATH: " + path);
//THIS IS HOW YOU GET THE NODE IN THE OTHER XML
XElement element = xmlNbidData.XPathSelectElement(path);
//AND THEN SET ITS VALUE !!!
element.Value = nodeValue;
}
TraverseNodes(node.ChildNodes);
}
}
这是运行时(示例):
GetRecursiveList - captureNode:hraPlan GetRecursiveList captureNode 父级:overallDeductible GetRecursiveList 名称|值:hraPlan | 是的
GetRecursiveList 捕获节点路径:createSbc/createSbcRequest/sbc/coreData/SBCDataContent/importantQuestions/overallDeductible/hraPlan
GetRecursiveList - captureNode: deductableCrossApply GetRecursiveList captureNode 父级:overallDeductible GetRecursiveList NAME|VALUE: deductableCrossApply | 不
GetRecursiveList 捕获节点路径:createSbc/createSbcRequest/sbc/coreData/SBCDataContent/importantQuestions/overallDeductible/deductableCrossApply
GetRecursiveList - captureNode:yearType GetRecursiveList captureNode 父:overallDeductible GetRecursiveList NAME|VALUE:yearType | 日历
GetRecursiveList 捕获节点路径:createSbc/createSbcRequest/sbc/coreData/SBCDataContent/importantQuestions/overallDeductible/yearType
GetRecursiveList - captureNode: individual GetRecursiveList captureNode Parent: inNetwork GetRecursiveList NAME|VALUE: individual | 0
GetRecursiveList 捕获节点路径:createSbc/createSbcRequest/sbc/coreData/SBCDataContent/importantQuestions/overallDeductible/inNetwork/individual