我正在尝试搜索Unity3D内部的XML文档(使用uJS和MSDN XmlDocument 类)来查找包含指定字符串的节点(在此测试中我正在寻找& #39;记录'),然后捕获匹配节点父名称属性的值。
但是我在路上的某个地方搞砸了;它当前正在传递所有节点的if语句(而不仅仅是那些匹配的节点),因此返回XML文档中的所有父名称。任何人都可以帮我理解我的逻辑吗?
非常感谢,
赖安
当前代码:
var mpo = xmlRoot.SelectNodes("MetaPipeObject");
for (var i = 0; i < mpo.Count; i++)
{
var curNode = mpo[i];
var nodeCheck = curNode.SelectNodes("//*[contains(text(), 'Logs')]");
Debug.Log("nodeCheck: " + nodeCheck.Count);
if (nodeCheck.Count > 1)
{
Debug.Log(curNode.SelectSingleNode("@name").Value);
}
}
}
&#13;
XML代码段
<MetaPipeObject name="Logs with graffiti">
<FileName>TestObj_EvanLogs04.obj</FileName>
<MeshLocation>/Users/ryanachten/Documents/UnityTests/MetaPipeline_TestModels/CRM_TestObjs/TestObj_EvanLogs/TestObj_EvanLogs04/TestObj_EvanLogs04.obj</MeshLocation>
<TexLocation>/Users/ryanachten/Documents/UnityTests/MetaPipeline_TestModels/CRM_TestObjs/TestObj_EvanLogs/TestObj_EvanLogs03/TestObj_EvanLogs.jpg</TexLocation>
<ObjImgCap>/Users/ryanachten/Documents/UnityTests/MetaPipeline/Assets/fuck you_ScreenShot.png</ObjImgCap>
<ContribName>Ryan Achten</ContribName>
<ContribDate>03/10/2015</ContribDate>
<Description>Logs with graffiti found out by Evan's Bay</Description>
<ModelInfo>
<ModelCreator>Ryan Achten</ModelCreator>
<ModelCreateDate>31/05/2015</ModelCreateDate>
<ModelCreateType>Photogrammetric</ModelCreateType>
</ModelInfo>
<ContextualInfo />
</MetaPipeObject>
<MetaPipeObject name="Punch (from Paul Jen">
<FileName>DaotfPunch03.obj</FileName>
<MeshLocation>/Users/ryanachten/Documents/UnityTests/MetaPipeline_TestModels/CRM_TestObjs/TestObj_DaotfPunch/DaotfPunch03/DaotfPunch03.obj</MeshLocation>
<TexLocation>/Users/ryanachten/Documents/UnityTests/MetaPipeline_TestModels/CRM_TestObjs/TestObj_DaotfPunch/DaotfPunch03/Punch_McorTex_merged.JPG</TexLocation>
<ObjImgCap>
</ObjImgCap>
<ContribName>Ryan Achten</ContribName>
<ContribDate>04/10/2015</ContribDate>
<Description>3D model of Judy based on Paul Jenden's costume concept illustrations for the project Digital Achives of the Future</Description>
<ModelInfo>
<ModelCreator>ard and Ryan Achten</ModelCreator>
<ModelCreateDate>26/02/2015</ModelCreateDate>
<ModelCreateType>Design</ModelCreateType>
</ModelInfo>
<ContextualInfo />
</MetaPipeObject>
&#13;
答案 0 :(得分:0)
XPath-expression //
从根元素开始搜索。在您的情况下,足以进行.//
- 从当前元素搜索。
var nodeCheck = curNode.SelectNodes(".//*[contains(text(), 'Logs')]");