/** <p>Tests marshalling of a complex element.</p>
*/
public void testMarshalComplexElements() throws Exception {
JAXBContext myFactory = getFactory();
JMMarshallerImpl marshaller = (JMMarshallerImpl) myFactory.createMarshaller();
marshaller.setXmlDeclaration(false);
StringWriter sw = new StringWriter();
Class c = marshaller.getXMLWriterClass();
XMLWriter w = (XMLWriter) c.newInstance();
w.init(marshaller);
String rawInput = getAllTypesElementString(false, true);
StringBuffer input = new StringBuffer();
for (int i = 0; i < rawInput.length(); i++) {
char ch = rawInput.charAt(i);
boolean done = false;
if (ch == '&') {
if (i+1 < rawInput.length() && rawInput.charAt(i+1) == '#') {
int j = 2;
StringBuffer digits = new StringBuffer();
while (i+j < rawInput.length() && Character.isDigit(rawInput.charAt(i+j))) {
digits.append(rawInput.charAt(i+j));
++j;
}
if (digits.length() > 0 &&
i+j < rawInput.length() && rawInput.charAt(i+j) == ';') {
char chr = (char) Integer.parseInt(digits.toString());
if (w.canEncode(chr)) {
done = true;
i += j;
input.append(chr);
}
}
}
}
if (!done) {
input.append(ch);
}
}
marshaller.marshal(getAllTypesElement(), sw);
assertEquals(input.toString(), sw.toString());
}