public static Document.Node GetNodeByName(Document.Node root, string sid) { if (root.sid == sid) { return(root); } if (root.children != null) { Document.Node node; foreach (Document.Node child in root.children) { node = GetNodeByName(child, sid); if (node != null) { return(node); } } } return(null); }
public static string GetTargetNodeId(Document doc, string targetAddress) { string[] addressParts = targetAddress.Split('/'); if (addressParts.Length == 0) { throw new ColladaException("invalid target address: " + targetAddress); } if (addressParts[0] == ".") { throw new ColladaException("can't handle relative target address:" + targetAddress); } if (!doc.dic.ContainsKey(addressParts[0])) { throw new ColladaException("can't find node " + addressParts[0]); } Document.Node targetNode = doc.dic[addressParts[0]] as Document.Node; for (int i = 1; i < addressParts.Length - 1; i++) { bool found = false; foreach (Document.Node node in targetNode.children) { if (node.sid == addressParts[i]) { targetNode = node; found = true; break; } } if (!found) { throw new ColladaException("invalid target address: " + targetAddress); } } return(targetNode.id); }