faris shomou

Greenhorn
+ Follow
since Apr 03, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by faris shomou

I do like to thank you again, the problem is each time my client change his namespace�s prefix, so I�m asking if I could eliminate all the namespaces dynamically and the I can use the xpath without prefixes:

String s =
(String)xpath.evaluate("//Acknowledgement//@Receiver", doc, XPathConstants.STRING);
Thank you for yore reponce.

The problem is that i do not know what is the prefix for the namesapace.

I want ust to use the xpath without the namesapace prefix.
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,

[email protected]
----------------------

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>