You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Garth Patil <ga...@gmail.com> on 2007/11/14 02:32:53 UTC

Controlling encoding/escaping of an attribute

Hi,
I am using xmlbeans to generate the xml that is posted to a web
service. The web service provider is rather picky about the
encoding/escaping of the content of one of the attributes.
Particularly, they ask that line feeds be terminated by &#10;
For example:
<request>
  <message text="This is the first line.&#10;This is the second
line.&#10;This is the third line."/>
</request>

If I try to just use a \r\n or a \n, that appears without modification
in the xml.
If I try to set the encoded value explicitly, xmlbeans converts the
leading ampersand to &amp;
How can I control the escaping of the attribute so that the line feed
character has this encoding?
Thanks,
Garth

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: Controlling encoding/escaping of an attribute

Posted by Wing Yew Poon <wp...@bea.com>.
Garth,
what you need is XmlOptionCharEscapeMap.
See
http://xmlbeans.apache.org/docs/2.1.0/reference/org/apache/xmlbeans/XmlO
ptionCharEscapeMap.html.
E.g.,

      XmlOptionCharEscapeMap escapes = new XmlOptionCharEscapeMap();
      escapes.addMapping('A', XmlOptionCharEscapeMap.HEXADECIMAL);
      escapes.addMapping('B', XmlOptionCharEscapeMap.DECIMAL);
      escapes.addMapping('>', XmlOptionCharEscapeMap.PREDEF_ENTITY);

      XmlOptions opts = new XmlOptions();
      opts.setSaveSubstituteCharacters(escapes);
      System.out.println(myXml.xmlText(opts));

      will result in:
      A being printed as &#x41;
      B being printed as &#66;
      > being printed as &gt; 

Cheers,
Wing Yew

-----Original Message-----
From: Garth Patil [mailto:garthpatil@gmail.com] 
Sent: Tuesday, November 13, 2007 5:33 PM
To: user@xmlbeans.apache.org
Subject: Controlling encoding/escaping of an attribute

Hi,
I am using xmlbeans to generate the xml that is posted to a web
service. The web service provider is rather picky about the
encoding/escaping of the content of one of the attributes.
Particularly, they ask that line feeds be terminated by &#10;
For example:
<request>
  <message text="This is the first line.&#10;This is the second
line.&#10;This is the third line."/>
</request>

If I try to just use a \r\n or a \n, that appears without modification
in the xml.
If I try to set the encoded value explicitly, xmlbeans converts the
leading ampersand to &amp;
How can I control the escaping of the attribute so that the line feed
character has this encoding?
Thanks,
Garth

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org