[
https://issues.apache.org/jira/browse/XMLBEANS-579?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alexander Pinske updated XMLBEANS-579:
--------------------------------------
Description:
When generating a sample, usually the top-level-element is xml-fragment. But
when the type contains only one child-element, it becomes the root.
{code:java}
import org.apache.xmlbeans.SchemaTypeSystem;
import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
public class SchemaTest {
private static String generateXml(String xsdString) throws XmlException
{
XmlOptions options = new
XmlOptions().setDocumentSourceName("a.xsd");
XmlObject xsd = SchemaDocument.Factory.parse(xsdString,
options);
SchemaTypeSystem schema = XmlBeans.compileXsd(new XmlObject[] {
xsd }, XmlBeans.getBuiltinTypeSystem(), options);
return
SampleXmlUtil.createSampleForType(schema.globalElements()[0].getType());
}
public static void main(String[] args) throws Exception {
String xml = generateXml(
"<?xml version=\"1.0\"
encoding=\"utf-8\"?><schema elementFormDefault=\"qualified\"
targetNamespace=\"x\" xmlns=\"http://www.w3.org/2001/XMLSchema\">"
+ " <element name=\"a\">" //
+ "
<complexType><sequence>" //
+ "
<element name=\"b\"><complexType><sequence>" //
+ "
<element name=\"c\" type=\"string\" />" //
+ "
</sequence></complexType></element>" //
+ "
</sequence></complexType>" //
+ " </element>" //
+ "</schema>");
System.out.println(xml);
}
}
{code}
Generates:
{code:xml}
<x:b xmlns:x="x">
<x:c>string</x:c>
</x:b>
{code}
Expected:
{code:xml}
<xml-fragment xmlns:x="x">
<x:b>
<x:c>string</x:c>
</x:b>
</xml-fragment>
{code}
was:
When generating a sample, usually the top-level-element is xml-fragment. But
when the type contains only one child-element, it becomes the root.
{code:java}
import org.apache.xmlbeans.SchemaTypeSystem;
import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
public class SchemaTest {
private static String generateXml(String xsdString) throws XmlException
{
XmlOptions options = new
XmlOptions().setDocumentSourceName("a.xsd");
XmlObject xsd = SchemaDocument.Factory.parse(xsdString,
options);
SchemaTypeSystem schema = XmlBeans.compileXsd(new XmlObject[] {
xsd }, XmlBeans.getBuiltinTypeSystem(), options);
return
SampleXmlUtil.createSampleForType(schema.globalElements()[0].getType());
}
public static void main(String[] args) throws Exception {
String xml = generateXml(
"<?xml version=\"1.0\"
encoding=\"utf-8\"?><schema elementFormDefault=\"qualified\"
targetNamespace=\"x\" xmlns=\"http://www.w3.org/2001/XMLSchema\">"
+ " <element name=\"a\">" //
+ "
<complexType><sequence>" //
+ "
<element name=\"b\"><complexType><sequence>" //
+ "
<element name=\"c\" type=\"string\" />" //
+ "
</sequence></complexType></element>" //
+ "
</sequence></complexType>" //
+ " </element>" //
+ "</schema>");
System.out.println(xml);
}
}
{code}
Generates:
{code:xml}
<x:b xmlns:x="x">
<x:c>string</x:c>
</x:b>
{code}
Expected:
{code:xml}
<xml-fragment xmlns:x="x">
<x:b>
<x:c>string</x:c>
</x:b>
</xml-fragment>
{code}
> SampleXmlUtil misses root element with only one child
> -----------------------------------------------------
>
> Key: XMLBEANS-579
> URL: https://issues.apache.org/jira/browse/XMLBEANS-579
> Project: XMLBeans
> Issue Type: Bug
> Affects Versions: Version 5.0.1
> Reporter: Alexander Pinske
> Priority: Major
>
> When generating a sample, usually the top-level-element is xml-fragment. But
> when the type contains only one child-element, it becomes the root.
> {code:java}
> import org.apache.xmlbeans.SchemaTypeSystem;
> import org.apache.xmlbeans.XmlBeans;
> import org.apache.xmlbeans.XmlException;
> import org.apache.xmlbeans.XmlObject;
> import org.apache.xmlbeans.XmlOptions;
> import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
> import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
> public class SchemaTest {
> private static String generateXml(String xsdString) throws XmlException
> {
> XmlOptions options = new
> XmlOptions().setDocumentSourceName("a.xsd");
> XmlObject xsd = SchemaDocument.Factory.parse(xsdString,
> options);
> SchemaTypeSystem schema = XmlBeans.compileXsd(new XmlObject[] {
> xsd }, XmlBeans.getBuiltinTypeSystem(), options);
> return
> SampleXmlUtil.createSampleForType(schema.globalElements()[0].getType());
> }
> public static void main(String[] args) throws Exception {
> String xml = generateXml(
> "<?xml version=\"1.0\"
> encoding=\"utf-8\"?><schema elementFormDefault=\"qualified\"
> targetNamespace=\"x\" xmlns=\"http://www.w3.org/2001/XMLSchema\">"
> + " <element name=\"a\">" //
> + "
> <complexType><sequence>" //
> + "
> <element name=\"b\"><complexType><sequence>" //
> + "
> <element name=\"c\" type=\"string\" />" //
> + "
> </sequence></complexType></element>" //
> + "
> </sequence></complexType>" //
> + " </element>" //
> + "</schema>");
> System.out.println(xml);
> }
> }
> {code}
> Generates:
> {code:xml}
> <x:b xmlns:x="x">
> <x:c>string</x:c>
> </x:b>
> {code}
> Expected:
> {code:xml}
> <xml-fragment xmlns:x="x">
> <x:b>
> <x:c>string</x:c>
> </x:b>
> </xml-fragment>
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]