protected AbstractConstruct(BinaryReader reader, ConstructCollection constructs) { if (reader == null) { throw new ArgumentNullException("reader"); } if (constructs == null) { throw new ArgumentNullException("construct"); } this.constructs = constructs; byte[] buffer = new byte[STR_LENGTH]; reader.Read(buffer, 0, STR_LENGTH); ParentName = Encoding.ASCII.GetString(buffer); ParentName = ParentName.Substring(0, ParentName.IndexOf('\0')); reader.Read(buffer, 0, STR_LENGTH); ChildName = Encoding.ASCII.GetString(buffer); ChildName = ChildName.Substring(0, ChildName.IndexOf('\0')); Origin = ConvertData.ToVector3(reader); }
public static XmlNode Find(XmlNode Node, string NamePath) { // ---------------------------------------------------- // Find a child with the specified NamePath. NamePath // can be a single child name or a path delimited with // '/' characters e.g. ChildNode/SubChildNode or /RootNode/ChildNode // Returns null if no child found. // ---------------------------------------------------- if (Node == null) { return(null); } if (NamePath == "") { throw new Exception("Cannot call FindByName with a blank path"); } if (NamePath[0] == Delimiter) { Node = Node.OwnerDocument.DocumentElement; int Pos = NamePath.IndexOf(Delimiter, 1); string RootName; if (Pos == -1) { RootName = NamePath.Substring(1); NamePath = ""; } else { RootName = NamePath.Substring(1, Pos - 1); NamePath = NamePath.Substring(Pos + 1); } if (RootName.ToLower() != Name(Node).ToLower()) { return(null); } if (NamePath == "") { return(Node); } } string ChildName, Remainder; int PosDelimiter = NamePath.IndexOf(Delimiter); if (PosDelimiter != -1) { ChildName = NamePath.Substring(0, PosDelimiter); Remainder = NamePath.Substring(PosDelimiter + 1); } else { ChildName = NamePath; Remainder = ""; } if (ChildName == "..") { return(Find(Node.ParentNode, Remainder)); } else if (ChildName.Length > 0 && ChildName[0] == '@') { return(Node.Attributes[ChildName.Substring(1)]); } else { foreach (XmlNode Child in Node.ChildNodes) { if (Name(Child).ToLower() == ChildName.ToLower()) { if (Remainder == "") { return(Child); } else { return(Find(Child, Remainder)); } } } } return(null); }