Why parser convert escape entities automatically?

Hi,
I'm parsing XML with JDK 1.4.2 + SAX(Crimson).
I found that parser converts some of escape entities, like ">", or "<", automatically.
I made a simple SAX application to show the trouble.
The full codes are the followings,
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SimpeXmlHandler extends DefaultHandler {
     private StringBuffer str = null;
     public void startElement(String namespaceURI, String localName,
               String qName, Attributes attributes) throws SAXException {
          str = new StringBuffer();
     public void endElement(String uri, String localName, String qName)
               throws SAXException {
          if (str != null) {
               if (qName.equalsIgnoreCase("tag")) {
                    System.out.println("tag=" + str.toString().trim());
     public void characters(char[] chars, int start, int length)
               throws SAXException {
          str.append(chars, start, length);
public class SimpleXmlTest {
     public static void main(String[] args) throws Exception {
          SimpeXmlHandler handler = new SimpeXmlHandler();
          SAXParserFactory factory = SAXParserFactory.newInstance();
          factory.setValidating(false);
          SAXParser parser = factory.newSAXParser();
          XMLReader xmlReader = parser.getXMLReader();
          xmlReader.setContentHandler(handler);
          InputStream in = new FileInputStream(new File("sample.xml"));
          InputSource source = new InputSource(in);
          xmlReader.parse(source);
}The XML sample is,
<?xml version="1.0" encoding="UTF-8"?>
<root>
     <tag>a&gt;b</tag>
</root>
After run SimpleXmlTest, the output was,
tag=a>b
The result isn't my want.
I don't want the parser converts the chars.
How to do?
P.S.
I also tried with DOM(Dom4J), it didn't work, too.
Thanks!
a cup of Java, cheers!
Sha Jiang

The XML parser will convert all entities before the data is returned (to the program) either as sax events or as DOM nodes.
Also an XML writer will (normally) convert all characters that would result in not well-formed XML back into entities.
So, yes this behaviour cannot be cancelled and yes this behaviour should make it actually easier to work with XML.

Similar Messages

  • Why doesn't Photoshop CS5 automatically scale strokes and effects?

    I am looking everywhere for why Photoshop CS5 doesn't automatically scale strokes and effects. I could've sworn there was a preference in CS4 but there's nothing resembling this in CS5. Driving me crazy!
    Whenever I do a Free Transform, the effects are completely out of whack and force me to waste time resetting them individually, layer by layer. I used to be able to grab any object or group of objects, do a transformation and Photoshop automatically recalculated. If anyone has a tip on how to avoid the annoyance of having to go layer by layer and forcibly adjusting that would be great.

    Layer style effect setting are in absolute pixel size values so if you change the scale of a layer the style size remains the same. You can edit the layers style effects after tou do a transform on the layer and change the absolute setting. If the layer has been rastersized or flattened you can not. I have request that Adobe add support for relative settings like inches, cm, mm etc which is relative to the documents dpi resolution. This would be very helpful for recording actions. 
    However photoshop can scale existing layer style for you when you use Image Size there is a check box.  If you need to scale a single layer and have its style scaled you need to do it in a round about way. Convert the layer to a smart object. Then instead of using transform double click on the layser smart object icon in the layers palette.  Photoshop will open that layer embedded smart object in Photoshop for you to work on it.. Use Image Size to resize the layer up or down in size and check resample constrain and the scale style check box.  Then use menu File>Save.  Photoshop will then update the embedded smart object in the smart object layer and you can close the document Photoshop opened for you to work on the smart object.

  • Why won't my Mac automatically connect to my preferred network?

    My router at home is one of my preferred networks but it won't connect automatically.  I always have to go up to the wifi menu and connect to Home manually.  Why won't it connect automatically?

    Try to drag the network to the top in the order of networks.
    System Preferences > Network > Advanced > Wi-Fi
    To delete the network,  select it and click "-" minus button underneath.

  • Why won't my mac automatically select my home network?

    Why can't my Mac AUTOMATICALLY connect to my wireless hub.  I get a message that the network can't be found.  This occured after I had to reset the hub and then had to re-setup the network.

    Go to  > System Preferences > Network, and select Wi-Fi. Click the Advanced… button and select the Wi-Fi tab.
    Under Preferred Networks, select your old network, or better yet select all that appear, and click the "–" (minus) button for each one. Check the box "Remember networks this computer has joined" if it is not already checked.
    OK then Apply.
    In your Mac's Wi-Fi icon, select your network and provide its password.
    Your Mac should now remember it.

  • Why are pdf files opened automatically in iPad email. I need to save the pdf file itself.

    Why are pdf files opened automatically in iPad email?  I need to save the pdf file itself, so I can re-read them for later.  ANy fix.  Some pdf files I send are saved as pdf files unopened.

    I have no idea how an iPad works.
    [topic moved to iOS subforum]

  • Why do certain applications open automatically

    why do certain applications open automatically?

    If you're using Lion, and the apps open automatically when you start up/log in, it's down to one of two things. Either
    a) you had the application open when you shut down last time, or
    b) you have that application set to open automatically.
    If you don't want (a) happening, either quit the application completely before you shut down, or turn off all app resuming through System Preferences - General - untick "Restore windows when quitting and re-opening apps".
    If the apps re-open even if you quit them before shutting down, check System Preferences - Accounts - Login Items. Delete any programs from the list that you don't want auto-launching when you log in.
    Matt

  • What is data roaming? Does it cost extra? Why doesn't my iPhone automati...

    What is data roaming? Does it cost extra?
    Why doesn't my iPhone automatically connect to AT&T service? Sometimes I have to go directly to Carriers in the Settings to connect to AT&T 3G. Thank you in advance.

    There is no local data roaming or call roaming in the U.S. as a subscriber with AT&T. Wherever AT&T has coverage in the U.S. is included.
    AT&T does not own all the towers in the areas where they have coverage in the U.S. AT&T calls this "off net usage"
    The following was copied from AT&T's wireless service agreement.
    +If your minutes of use (including unlimited services) on other carrier networks ("off-net usage") during any two consecutive months exceed your off-net usage allowance, AT&T may, at its option terminate your service, deny your continued use of other carriers' coverage or change your plan to one imposing usage charges for off-net usage. Your off-net usage allowance is equal to the lesser of 750 minutes or 40% of the Anytime Minutes included with your plan. AT&T will provide notice that it intends to take any of the above actions, and you may terminate the agreement.+

  • Why Firefox not Sync will automatically showing unknown error?

    why Firefox not Sync will automatically showing unknown error?

    How long has been this happening? Have you tried again?
    I will encourage you to use the recommendations on this article whenever Sync returns Unknown errors for a long period of time.
    [[Firefox Sync is not working]]
    Sometimes it's just as simple as a connection issue between your computer and the servers.

  • Why does photoshop download pictures automatically off the internet that I don't want?

    why does photoshop download pictures automatically off the internet that I don't want?

    Where are the pictures coming from? I would more likely believe that your system has a virus than photoshop, but without more information, I could be misinterpreting your post.

  • HT1848 How do I sync my music on my computer to my iPhone - why does this not happen automatically when I connect?

    How do I sync my music on my computer to my iPhone - why does this not happen automatically when I connect?

    Do you have iTunes set to sync music to the device?
    Have you read the User's Guide that explains how to use the device?
    Syncing media and content to iDevices

  • Why my ipad restart itself automatically

    Why my ipad restart itself automatically

    (A) Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.
    (B) Reset all settings
    Settings>General>Reset>Reset all settings
    Note: Data will not be affected but settings will be reset.

  • HT3529 I'm sending an iMessage from my iPhone to another iPhone but the recipient phone does not receive message because not on wifi. Why does recipient iPhone not automatically receive in text messaging?

    I'm sending an iMessage from my iPhone to another iPhone but the recipient phone does not receive message because not on wifi. Why does recipient iPhone not automatically receive in text messaging?

    Wi-Fi is not required for iMessage. Internet access is required for iMessage which includes when the iPhone is connected to the cellular network.
    If an iMessage cannot be sent, it will fail to send and you will be prompted to send as an SMS if text only.

  • If i upload a doc to iCloud from my iMac and if i change it on my notebook whys isn't it then automatically updated on my Mac??

    If i upload a doc to iCloud from my iMac and if i change it on my notebook whys isn't it then automatically updated on my Mac??

    Welcome to the Apple community.
    It isn't automatically updated on your Mac, because it's not on your Mac.
    The document you have altered is in the cloud and needs re-downloading from iCloud.com, before you can see the changes on your Mac.

  • Why will audiobooks not download automatically to other devices

    Why will audiobooks not download automatically to other devices?
    I always have to connect to home computer and sync!

    Audiobooks are currently a one-time only download so they are not included in the automatic downloads. You will need to sync them to get them onto other devices/computers

  • Why won't my homepage automatically come up with i use my browser

    Why won't my homepage automatically come up when I go online

    Click on Safari then prefernces and type in the homepage you want to load. or do the same with any browser.

Maybe you are looking for