I just got a JAXB variant working:
public class XmlParser
{
@XmlRootElement( name = "string", namespace = "http://tempuri.org/" )
@XmlAccessorType( XmlAccessType.FIELD )
static class MyString
{
@XmlValue
String string;
}
@XmlRootElement( name = "MyList" )
@XmlAccessorType( XmlAccessType.FIELD )
static class MyList
{
@XmlElement( name = "Obj" )
List<String> objs = new ArrayList<>();
}
public static void main( String[] args ) throws JAXBException
{
String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<string xmlns=\"http://tempuri.org/\"><?xml version=\"1.0\" encoding=\"utf-8\" ?><MyList><Obj>Im obj 1</Obj><Obj>Im obj1</Obj></MyList></string>";
JAXBContext context = JAXBContext.newInstance( MyString.class, MyList.class );
Unmarshaller unmarshaller = context.createUnmarshaller();
MyString myString = (MyString) unmarshaller.unmarshal( new StringReader( s ) );
MyList myList = (MyList) unmarshaller.unmarshal( new StringReader( myString.string ) );
System.out.println( myList.objs );
}
}