Exemple #1
0
def DoXPath (Filename,XPathString):
	IS = InputSource (FileInputStream (Filename))
	df = DocumentBuilderFactory.newInstance()
	df.setNamespaceAware(1)
	doc = df.newDocumentBuilder().parse(IS)
	serializer = TransformerFactory.newInstance().newTransformer()
	serializer.setOutputProperty (OutputKeys.OMIT_XML_DECLARATION, "yes")
	nl = XPathAPI.selectNodeIterator (doc,XPathString)
	n = nl.nextNode()
	while n:
		if IsTextNode (n):
			# Coalesce contiguous text nodes
			res = [n.getNodeValue()]
			nn = n.getNextSibling()
			while (nn):
				res.append (nn.getNodeValue())
				nn = n.getNextSibling()
			java.lang.System.out (string.join(res,""))
		else:
			serializer.transform (DOMSource(n), StreamResult (OutputStreamWriter (java.lang.System.out)))
		java.lang.System.out.println()
		n = nl.nextNode()
def getChildElements(node, childName):
    return NodeList(XPathAPI.selectNodeList(node._impl, childName))
def getChildElements(node, childName):
    return NodeList(XPathAPI.selectNodeList(node._impl, childName))
def getChild(node, childName):
    return _wrap_node(XPathAPI.selectSingleNode(node._impl, childName))
def getChild(node, childName):
    return _wrap_node(XPathAPI.selectSingleNode(node._impl, childName))