RE: XML Beans - Escape Chars

Wing Yew Poon <[email protected]>
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <3ca7e8b3-6b5f-4bef-98c8-747908c79b86@default>
<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 "&amp;".

The setSaveSubstituteCharacters option has nothing to do
with unmarshalling, only with marshalling.

-----Original Message-----
From: YesKay [mailto:[email protected]] 
Sent: Wednesday, December 16, 2009 8:34 AM
To: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.