XmlObject[] schemas = new XmlObject[] {XmlObject.Factory.parse(schema)}; XmlBeans.loadXsd(schemas); SchemaTypeSystem typeSystem = XmlBeans.typeSystemForClassLoader(MyClass.class.getClassLoader()); SchemaType schemaType = typeSystem.findType(new QName(namespaceURI, complexTypeName)); Class javaClass = schemaType.getJavaClass();
String xml = "This example shows how to use the XmlBeans library to parse an XML document and convert it into a Java object. The first line creates a string with our XML data. The second line uses the XmlObject.Factory class to parse the XML data into an XmlObject instance. The third line changes the type of the XmlObject to the specific schema type we are interested in, in this case the PersonType. Finally, we obtain a Java object of the PersonType by casting the XmlObject to the appropriate Java class. The org.apache.xmlbeans XmlBeans library is part of the Apache XML project, and is available as a Java package library."; XmlObject xmlObject = XmlObject.Factory.parse(xml); PersonType person = (PersonType) xmlObject.changeType(PersonType.type); John 30