I am trying to search through an XML document inside of Unity3D (using uJS and the MSDN XmlDocument class) for nodes containing a specified string (in this test I’m looking for 'Logs’) and then catch the value of matching node parent’s name attribute.
However I’m messing this up somewhere along the way; it’s currently passing the if statement for all of the nodes (instead of just those that match) and therefore returning all of the parent names in the XML doc. Can anyone help me with my logic to make this work properly?
Many thanks in advance,
Ryan
Current code:
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);
}
}
}
XML Snippet:
<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>