Topic
2 replies Latest Post - ‏2007-05-01T12:56:12Z by SystemAdmin
SystemAdmin
SystemAdmin
28 Posts
ACCEPTED ANSWER

Pinned topic Things about escapes

‏2007-04-30T09:18:09Z |
Hi, I am using JAXP parsing some xml files,
however I found all "&#xD"s in xml source are converted as "\n" in the parsed java String. Is there any switches that forbid the parser to do this automatic transforming?
My code is like below:

DocumentBuilder builder;
Document doc = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
builder = factory.newDocumentBuilder();
doc = builder.parse(input);

...
Thanks.
Updated on 2007-05-01T12:56:12Z at 2007-05-01T12:56:12Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    28 Posts
    ACCEPTED ANSWER

    Re: Things about escapes

    ‏2007-04-30T13:58:15Z  in response to SystemAdmin
    You're describing the usual whitespace normalization process on XML parse, so there is probably no way to turn it off. If you absolutely must maintain "&#xD" characters one workaround is to convert them to another character before parse, perhaps something in the Unicode private use area, just to be safe. You can then convert then back to "&#xD" whenever you need the actual character data. Yes this is a hack, but there's not much you can do when you're fighting the purposeful limitations in XML 1.0.
    • SystemAdmin
      SystemAdmin
      28 Posts
      ACCEPTED ANSWER

      Re: Things about escapes

      ‏2007-05-01T12:56:12Z  in response to SystemAdmin
      Hey, thank you, uche.
      I would try your way of hack. But still very frustrated about the xml standard...