/// <summary> /// Locates all the child elements of the given parent <see cref="XmlElement"/> /// and returns them in a (possibly empty) <see cref="XmlNodeList"/>. /// </summary> /// <param name="parent">The parent <see cref="XmlElement"/>.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of child elements.</returns> public static XmlNodeList GetChildElements(XmlElement parent) { MutableNodeList list = new MutableNodeList (); if (parent != null) { foreach (XmlNode node in parent.ChildNodes) if (node.NodeType == XmlNodeType.Element) list.Add (node); } return (list); }
/// <summary> /// Creates a (possibly empty) <see cref="XmlNodeList"/> containing all the /// element nodes of a given type (or a derived subtype). /// </summary> /// <param name="ns">The required namespace URI.</param> /// <param name="type">The required type.</param> /// <returns>A <see cref="XmlNodeList"/> of corresponding nodes.</returns> public XmlNodeList GetElementsByType(string ns, string type) { List <XmlSchemaType> matches; if (!compatibleTypes.ContainsKey(type)) { compatibleTypes.Add(type, matches = new List <XmlSchemaType> ()); // System.err.println ("%% Looking for " + ns + ":" + type); foreach (string key in typesByName.Keys) { List <XmlSchemaType> types = typesByName [key]; foreach (XmlSchemaType info in types) { if (type.Equals(info.Name) || IsDerived(new XmlQualifiedName(type, ns), info)) { matches.Add(info); // System.err.println ("%% Found: " + info.getTypeName ()); } } } } else { matches = compatibleTypes [type]; } MutableNodeList result = new MutableNodeList(); foreach (XmlSchemaType info in matches) { // System.err.println ("-- Matching elements of type: " + info.getTypeName ()); if (elementsByType.ContainsKey(info.Name)) { foreach (XmlElement element in elementsByType[info.Name]) { XmlSchemaType typeInfo = element.SchemaInfo.SchemaType; if (typeInfo.QualifiedName.Equals(info.QualifiedName)) { result.Add(element); // System.err.println ("-- Matched: " + element.getLocalName ()); } } } } return(result); }
/// <summary> /// Locates all the child <see cref="XmlElement"/> instances of the indicated /// parent that match the given local name string, ignoring prefixes /// and namespaces. /// </summary> /// <param name="parent">The parent <see cref="XmlElement"/>.</param> /// <param name="localName">The required element local name string.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of matching /// <see cref="XmlElement"/> instances.</returns> public static XmlNodeList GetElementsByLocalName(XmlElement parent, string localName) { MutableNodeList list = new MutableNodeList(); foreach (XmlNode node in parent.ChildNodes) { if ((node.NodeType == XmlNodeType.Element) && node.LocalName.Equals(localName)) { list.Add(node); } } return(list); }
/// <summary> /// Locates all the child elements of the given parent <see cref="XmlElement"/> /// and returns them in a (possibly empty) <see cref="XmlNodeList"/>. /// </summary> /// <param name="parent">The parent <see cref="XmlElement"/>.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of child elements.</returns> public static XmlNodeList GetChildElements(XmlElement parent) { MutableNodeList list = new MutableNodeList(); if (parent != null) { foreach (XmlNode node in parent.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { list.Add(node); } } } return(list); }
//--------------------------------------------------------------------------- /// <summary> /// Evaluates a simple multiple valued path access from the given context /// node to the named child elements. The '*', '.' and '..' specifiers are /// supported. /// </summary> /// <param name="context">The context <see cref="XmlElement"/>.</param> /// <param name="name">The name of the required child.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of matching /// child elements.</returns> public static XmlNodeList Paths(XmlElement context, string name) { if (context != null) { if (name.Equals("*")) { return((context != null) ? DOM.GetChildElements(context) : MutableNodeList.EMPTY); } else if (name.Equals(".")) { if (context != null) { MutableNodeList list = new MutableNodeList(); list.Add(context); return(list); } else { return(MutableNodeList.EMPTY); } } else if (name.Equals("..")) { if ((context != null) && (context.ParentNode != null)) { MutableNodeList list = new MutableNodeList(); list.Add(context.ParentNode); return(list); } else { return(MutableNodeList.EMPTY); } } return(DOM.GetElementsByLocalName(context, name)); } return(MutableNodeList.EMPTY); }
/// <summary> /// Validates all the elements registered at construction using the /// <see cref="NodeIndex"/> to locate them as quickly as possible. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the test document.</param> /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param> /// <returns><c>true</c> if the code values pass the checks, <c>false</c> /// otherwise.</returns> protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; for (int index = 0; index < elementNames.Length; ++index) { XmlNodeList list = nodeIndex.GetElementsByName (elementNames [index]); if (parentNames == null) result &= Validate (list, errorHandler); else { MutableNodeList targets = new MutableNodeList (); foreach (XmlElement context in list) { XmlNode parent = context.ParentNode; if ((parent.NodeType == XmlNodeType.Element) && parent.LocalName.Equals (parentNames [index])) targets.Add (context); } result &= Validate (targets, errorHandler); } } return (result); }
/// <summary> /// Locates all the child <see cref="XmlElement"/> instances of the indicated /// parent that match the given local name string, ignoring prefixes /// and namespaces. /// </summary> /// <param name="parent">The parent <see cref="XmlElement"/>.</param> /// <param name="localName">The required element local name string.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of matching /// <see cref="XmlElement"/> instances.</returns> public static XmlNodeList GetElementsByLocalName(XmlElement parent, string localName) { MutableNodeList list = new MutableNodeList (); foreach (XmlNode node in parent.ChildNodes) { if ((node.NodeType == XmlNodeType.Element) && node.LocalName.Equals (localName)) list.Add (node); } return (list); }
/// <summary> /// Creates a (possibly empty) <see cref="XmlNodeList"/> containing all the /// element nodes of a given type (or a derived subtype). /// </summary> /// <param name="ns">The required namespace URI.</param> /// <param name="type">The required type.</param> /// <returns>A <see cref="XmlNodeList"/> of corresponding nodes.</returns> public XmlNodeList GetElementsByType(string ns, string type) { List<XmlSchemaType> matches; if (!compatibleTypes.ContainsKey (type)) { compatibleTypes.Add (type, matches = new List<XmlSchemaType> ()); // System.err.println ("%% Looking for " + ns + ":" + type); foreach (string key in typesByName.Keys) { List<XmlSchemaType> types = typesByName [key]; foreach (XmlSchemaType info in types) { if (type.Equals (info.Name) || IsDerived (new XmlQualifiedName (type, ns), info)) { matches.Add (info); // System.err.println ("%% Found: " + info.getTypeName ()); } } } } else matches = compatibleTypes [type]; MutableNodeList result = new MutableNodeList (); foreach (XmlSchemaType info in matches) { // System.err.println ("-- Matching elements of type: " + info.getTypeName ()); if (elementsByType.ContainsKey (info.Name)) { foreach (XmlElement element in elementsByType [info.Name]) { XmlSchemaType typeInfo = element.SchemaInfo.SchemaType; if (typeInfo.QualifiedName.Equals (info.QualifiedName)) { result.Add (element); // System.err.println ("-- Matched: " + element.getLocalName ()); } } } } return (result); }
//--------------------------------------------------------------------------- /// <summary> /// Evaluates a simple multiple valued path access from the given context /// node to the named child elements. The '*', '.' and '..' specifiers are /// supported. /// </summary> /// <param name="context">The context <see cref="XmlElement"/>.</param> /// <param name="name">The name of the required child.</param> /// <returns>A possibly empty <see cref="XmlNodeList"/> of matching /// child elements.</returns> public static XmlNodeList Paths(XmlElement context, string name) { if (context != null) { if (name.Equals ("*")) return ((context != null) ? DOM.GetChildElements (context) : MutableNodeList.EMPTY); else if (name.Equals (".")) { if (context != null) { MutableNodeList list = new MutableNodeList (); list.Add (context); return (list); } else return (MutableNodeList.EMPTY); } else if (name.Equals ("..")) { if ((context != null) && (context.ParentNode != null)) { MutableNodeList list = new MutableNodeList (); list.Add (context.ParentNode); return (list); } else return (MutableNodeList.EMPTY); } return (DOM.GetElementsByLocalName (context, name)); } return (MutableNodeList.EMPTY); }