I�m trying to pars un xml file (below), with setting �setNamespaceAware(false)�
My
string s is always empty, I do not why.
I someone can help me, thanks in advance,
fshomou@hotmail.com ----------------------
My xml file:
<?xml version="1.0" encoding="UTF-8"?>
<fs:Faris xmlns:fs="http://www.test.com">
<fs:Acknowledgement Receiver="salam" Sender="faris">
<fs:UUId>12322222</fs:UUId>
</fs:Acknowledgement>
</fs:Faris>
my code:
----------------------------------------------------
// JAXP
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
// DOM
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document
doc = builder.parse(new File("C:\\mytest.xml"));
XPath xpath;
xpath = XPathFactory.newInstance().newXPath();
String s = (String)xpath.evaluate("//Acknowledgement//@Receiver", doc,
XPathConstants.STRING);
System.out.println(s);
---------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<fs:Faris xmlns:fs="http://www.test.com">
<fs:Acknowledgement Receiver="salam" Sender="faris">
<fs:UUId>12322222</fs:UUId>
</fs:Acknowledgement>
</fs:Faris>