You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by YesKay <ke...@yahoo.com> on 2009/12/16 17:33:48 UTC
XML Beans - Escape Chars
I'm trying to escaping & char and getting below exception... just wondering
what am I doing wrong? Any help will be greatly appreciated. Here is my
program.
Exception ==>
org.apache.xmlbeans.XmlException: error: Unexpected character encountered
(lex state 3): ' '
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3471)
at org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:706)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:690)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:677)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:208)
at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:633)
Program ==>
public class XMLBeansEscapeChars
{
public static void main(String[] args)
{
try
{
String str = "<name>First Name & Last Name</name>";
XmlOptionCharEscapeMap escapes = new XmlOptionCharEscapeMap();
escapes.addMapping('&', XmlOptionCharEscapeMap.PREDEF_ENTITY);
XmlOptions xmlOpts = new XmlOptions();
xmlOpts.setSaveSubstituteCharacters(escapes);
XmlObject xmlObj = XmlObject.Factory.parse(str, xmlOpts);
System.out.println(xmlObj.xmlText());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
--
View this message in context: http://old.nabble.com/XML-Beans---Escape-Chars-tp26813900p26813900.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
RE: XML Beans - Escape Chars
Posted by Wing Yew Poon <wi...@oracle.com>.
<name>First Name & Last Name</name>
is simply not valid xml.
That is why you get an exception when you try to parse it.
The '&' needs to be escaped, e.g., as "&".
The setSaveSubstituteCharacters option has nothing to do
with unmarshalling, only with marshalling.
-----Original Message-----
From: YesKay [mailto:keerthipati@yahoo.com]
Sent: Wednesday, December 16, 2009 8:34 AM
To: user@xmlbeans.apache.org
Subject: XML Beans - Escape Chars
I'm trying to escaping & char and getting below exception... just wondering
what am I doing wrong? Any help will be greatly appreciated. Here is my
program.
Exception ==>
org.apache.xmlbeans.XmlException: error: Unexpected character encountered
(lex state 3): ' '
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3471)
at org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:706)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:690)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:677)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:208)
at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:633)
Program ==>
public class XMLBeansEscapeChars
{
public static void main(String[] args)
{
try
{
String str = "<name>First Name & Last Name</name>";
XmlOptionCharEscapeMap escapes = new XmlOptionCharEscapeMap();
escapes.addMapping('&', XmlOptionCharEscapeMap.PREDEF_ENTITY);
XmlOptions xmlOpts = new XmlOptions();
xmlOpts.setSaveSubstituteCharacters(escapes);
XmlObject xmlObj = XmlObject.Factory.parse(str, xmlOpts);
System.out.println(xmlObj.xmlText());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
--
View this message in context: http://old.nabble.com/XML-Beans---Escape-Chars-tp26813900p26813900.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org