public GetElementsByType ( string ns, string type ) : |
||
ns | string | The required namespace URI. |
type | string | The required type. |
return |
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 this <see cref="Precondition"/> against the contents of the /// indicated <see cref="NodeIndex"/>. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of a <see cref="XmlDocument"/></param> /// <param name="cache">A cache of previously evaluated precondition results.</param> /// <returns>A <see cref="bool"/> value indicating the applicability of this /// <see cref="Precondition"/> to the <see cref="XmlDocument"/>.</returns> public override bool Evaluate(NodeIndex nodeIndex, Dictionary<Precondition, bool> cache) { if (nodeIndex.HasTypeInformation) { string ns = FpMLRuleSet.DetermineNamespace (nodeIndex); foreach (string type in types) { XmlNodeList list = nodeIndex.GetElementsByType (ns, type); if ((list != null) && (list.Count > 0)) return (true); } } else { foreach (String element in elements) { XmlNodeList list = nodeIndex.GetElementsByName (element); if ((list != null) && (list.Count > 0)) return (true); } } return (false); }