代码段3:
<?xml version="1.0" encoding="UTF-8" ?> <wml> <!--简单的WML文件--> <card id="first"> <p> First card. </p> </card> <card id="second"> <p> First para of the Second card. </p>
<p> Second para of the Second card. </p>
</card> <!--可以在下面放入其它的card--> </wml> | 代码段4:
public class XPathExpression { DOM_Document XML_DOM; Array of Strings XPathLocationStepStringsArray; Array of XPathLocationSteps XPathLocationStepsArray; Array of XPathResults ResultNodeSet;
XPathExpression (string XMLFile, string XPathExpression) { XML_DOM = XMLFile loaded into a DOM; FunctionName = If there is any XPath function in the begining of the query, store the function name here; Strip the function name from the expression.
XPathLocationStepStringsArray = Tokenize XPath expression into smaller strings, where each string is a location step. Also unabbreviate any XPath abbreviations found;
Integer locationStepCount = Number of location step strings in XPathLocationStepStringsArray; String IndividualXPathLocationStepString; XPathLocationStep IndividualXPathLocationStep;
ResultNodeSet = XML_DOM loaded into an array of XPathResults.
Repeat locationStepCount times from i = 0 to locationStepCount-1: { IndividualXPathLocationStepString = XPathLocationStepStringsArray[i]; IndividualXPathLocationStep = a new object of XPathLocationStep( IndividualXPathLocationStepString, XML_DOM ); ResultNodeSet = IndividualXPathLocationStep.getResult(ResultNodeSet); }
Apply the XPath function on the resulting node-set
}
XPathExpression (DOM_Document XML_DOM, string XPathExpression) { Same as the first constructor, except that it takes the XML file as a DOM object instead of a string.
}
public Array of XPathResults getResult() { return ResultNodeSet; } } | 代码段5:
public class XPathLocationStep { String Axis; String NodeTest; Array of XPathResults OutputNodeSet; String FunctionName; String Predicate; DOM_Document XML_DOM;
XPathLocationStep(String XPathLocationStepString, DOM_Document XML_DOM_Document) { Resolve the XPathLocationStepString into FunctionName, Axis, NodeTest, and Predicate; XML_DOM = XML_DOM_Document; }
Array of XPathResults getResult(Array of Nodes ContextNodeSet) { OutputNodeSet = new Array of XPathResults;
Integer NodeCount =Number of nodes in ContextNodeSet; if (Axis is equal to "child" or "descendant") { Repeat NodeCount times for i = 0 to NodeCount-1 { Node node = ContextNodeSet[i]; Integer ChildCount = Number of node's children; Repeat ChildCount times for j = 0 to ChildCount-1 { Node ChildNode =node.getChildElement(j); String ChldName =Name of the ChildNode; if (NodeTest is equal to ChildName) Add ChildNode to OutputNodeSet; if (Axis is equal to "descendant") { Array of Nodes Descendants =getMatchingDescendants(ChildNode); Add MatchingDescendants to OutputNodeSet; } } } }
Predicate predicateEvaluator = new Predicate(OutputNodeSet, XML_DOM); OutputNodeSet = predicateEvaluator.getResult(); return OutputNodeSet;
}
private Array of Nodes getMatchingDescendants(Node node) { Array of Nodes MatchingDescendants; Integer ChildCount = Number of node's children; Repeat NodeCount times for j = 0 to ChildCount-1 { Node ChildNode =node.getChildElement(j); String ChildName =Name of the ChildNode; if (NodeTest is equal to ChildName) Add ChildNode to MatchingDescendants;
Array of Nodes MoreDescendants =getMatchingDescendants(ChildNode); Add MoreDescendants to MatchingDescendnts; } return MatchingDescendants; }
} | 代码段6:
public class XPathResult { string ResultType = "ArrayOfNodes";
string getResultType { return ResultType;
}
public setResultType (string Type) { ResultType = Type; } }
| 代码段7:
public class Predicate { Array of XPathResults ResultSet;
Predicate(Array of XPathResults ResultSet, DOM_Document XML_DOM) { Check if this predicate is just a logical condition or a complete XPath query. If it is a complete XPath expression { ResultSet = (new XPathExpression(XML_DOM, XPath Expression)) .getResult(); } else { ResultSet = Filtered result set; } }
Array of XPathResults getResult() { return ResultSet; }
}
|
|
|