java - using conditions in XPath expressions -
I need to parse an XML document in the database and there is a given expression in it, after that, String value must be returned if the given expression is present in XML, then I need to parse the next expression and another string value will be returned.
I have received it using the following code:
// An XML document is passed as a node when the getEntryType () method is public static The class is called XMLTextFields {public static string interrupts the inner type (node target) XPathExpressionException {XPathFactory Factory = XPathFactory.newInstance (); XPath xpath = factory.newXpath (); String entry type = null; String [] expression = new string [] {"./libx:package", "./libx:libapp", "./libx:module"}; String [] type = new string [] {"package", "libp", "module"}; (XPathExpression expr = xpath.compile (expression [i]); object results = expr.evaluate (target, XPathConstants.NODESET); nodelist nodes = (for int i = 0; i & lt; 3; i ++) Nodelist) result; if (nodes.getLength () == 0) is continued; entry type = (type [i]);} return entry type;}}
I am thinking Is that an easy way to do this? Meaning, there is a way to use "expression", which gives a string if the expression is present in XML.
I think that Should be able to do something like that, but I'm not sure exactly:
string [] expression = new string [] {"[./libx:package] \" package \ " ", ....}
If you have XPath processor version 2, you can use expressions:.
Comments
Post a Comment