[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to escape &dt=... (org.dom4j.DocumentException)
>> >> One of my xml nodes contains an url that contains the text &dt=... >> >> When I try to parse this via DocumentHelper.parseText I get >> the following exception: >> org.dom4j.DocumentException: Error on line 21 of document : >> The reference to entity "dt" must end with the ';' delimiter. > Either the text contains & rather than & - or you have put the text > through the parser twice. > Michael Kay I found out what the problem is, but not yet a nice way to solve it: I get an org.w3c.dom.Element from an external source, this contains an XML document what I have to handle. However this XML data has to be send remotely to our server and the main processing is done there. So what I do is: - I convert the org.w3c.dom.Element to a String of the whole XML document and send it to the remote server. The code that recieves the Element, converts it to String and sends it has to be as simple as possible (no import of other jar files unless absolutely necessary) and has to be fast. I tried some javax code to convert the Element to a string but it is extremely slow and takes about the same time as it takes to send the xml to the server, process it and return a result. So I constructed the XML String manually which is really fast. However when I do this and retrieve the node content with Node.getNodeValue() it returns the value unencoded. On the server side the XML is parsed to a Document again and handled there. This parsing fails because the URL mentioned is sent unencoded, thus i get the mentioned Exception. What I need to do now is encode the text I get from getNodeValue(). I tested it with replaceAll("&", "&") and that solved the problem, however this is a very incomplete way of handling it. Is there a method built into java that encodes the node value properly? Thanx in advance, Lukas
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|