You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just started to work with Android devices and parsing of XML data, so I'm struggling a bit but loving it.
We have an application written for Windows devices, which is being converted to Android. The old code includes an XSD file which is converted to Java Classes using the "xjc" tool. I plan to use Simple XML on the Android devices so I was really scratching my head, on how to generate the classes, until I discovered your fantastic application.
One problem I came across was our use of xs:dateTime in the XSD file.
I got that to work by modifying the "getJType" method in the "SchemaParser.java" file. I added this:
} else if ("dateTime".equals(type)) {
return codeModel._ref(Date.class);
to the end of the "if" block. Not sure if I need to do any more than that but it least appears to be doing the right thing now.
The next problem I've run into is the use of patterns in a xs:simpleType block.
We have something that looks like:
but, unfortunately, your application doesn't like it. If I add this "simpleType" to the bottom of your test.xsd file, and then add a new element to your "Person" complexType, i.e.
<xsd:element name="PatternTest" type="PatternB" />
I then get this output:
C:\Tony\xml\android>java -jar android-jaxb-1.0.jar -b bindings.json -d . -p com.example.tony test2.xsd
Reading bindings ...
Code Generator Initialized. Destination Directory: .
[Element /Person Min Occurs: null, Max Occurs: null ] of type [Person][Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/FirstName Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/LastName Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Adult Min Occurs: 0, Max Occurs: 1 ] of type [boolean]
[Element /Person/Addresses Min Occurs: 0, Max Occurs: 1 ] of type [Addresses] [Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/Addresses/Address Min Occurs: 0, Max Occurs: -1 ] of type [Address] [Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/Addresses/Address/Line1 Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/Line2 Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/City Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/State Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/Country Min Occurs: 1, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/PostalCode Min Occurs: 0, Max Occurs: 1 ] of type [string]
[End of sequence]
[End of sequence]
[Element /Person/Gender Min Occurs: 0, Max Occurs: 1 ] of type [Gender][Values = MALE, FEMALE, NOT_SPECIFIED]
[Element /Person/Favorite_Fruits Min Occurs: 0, Max Occurs: 3 ] of type [Fruits][Values = Apple, Banana, Mango, Orange, Grapes, Watermelon, Peach, Apricot, Grapefruit]
[Element /Person/SomeThing_really_whacky-by-the-user Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/PatternTest Min Occurs: 1, Max Occurs: 1 ] of type [actionCodeType][Pattern(s) = ((Update|Delete))]
Exception in thread "main" java.lang.NullPointerException
at com.sun.codemodel.JVar.annotate(JVar.java:188)
at com.mickoo.xml.xsd2simplexml.GeneratedClass.addElement(GeneratedClass.java:62)
at com.mickoo.xml.xsd2simplexml.SchemaParser.addSimpleType(SchemaParser.java:276)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processElement(SchemaParser.java:348)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processParticle(SchemaParser.java:208)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processGroup(SchemaParser.java:219)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processParticle(SchemaParser.java:204)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processComplexType(SchemaParser.java:232)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processElement(SchemaParser.java:344)
at com.mickoo.xml.xsd2simplexml.SchemaParser.parse(SchemaParser.java:67)
at com.mickoo.xml.xsd2simplexml.Main.main(Main.java:80)
It looks like it's parsing the XSD file correctly but maybe something is not being configured for the call to JVar.annotate. I'm trying to figure it out but I'm still a bit of a novice with Java.
Have you had any success with working with patterns, or maybe you haven't had a need to do a lot of testing with them? Hopefully it won't take too much of your time to help me with these patterns.
Anyway, thank you very much for a fabulous tool, it is very much appreciated.
Cheers from Down Under,
Tony
The text was updated successfully, but these errors were encountered:
Received via Email from Tony.
Hello Yeshodhan,
I've just started to work with Android devices and parsing of XML data, so I'm struggling a bit but loving it.
We have an application written for Windows devices, which is being converted to Android. The old code includes an XSD file which is converted to Java Classes using the "xjc" tool. I plan to use Simple XML on the Android devices so I was really scratching my head, on how to generate the classes, until I discovered your fantastic application.
One problem I came across was our use of xs:dateTime in the XSD file.
I got that to work by modifying the "getJType" method in the "SchemaParser.java" file. I added this:
} else if ("dateTime".equals(type)) {
return codeModel._ref(Date.class);
to the end of the "if" block. Not sure if I need to do any more than that but it least appears to be doing the right thing now.
The next problem I've run into is the use of patterns in a xs:simpleType block.
We have something that looks like:
but, unfortunately, your application doesn't like it. If I add this "simpleType" to the bottom of your test.xsd file, and then add a new element to your "Person" complexType, i.e.
<xsd:element name="PatternTest" type="PatternB" />
I then get this output:
C:\Tony\xml\android>java -jar android-jaxb-1.0.jar -b bindings.json -d . -p com.example.tony test2.xsd
Reading bindings ...
Code Generator Initialized. Destination Directory: .
[Element /Person Min Occurs: null, Max Occurs: null ] of type [Person][Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/FirstName Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/LastName Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Adult Min Occurs: 0, Max Occurs: 1 ] of type [boolean]
[Element /Person/Addresses Min Occurs: 0, Max Occurs: 1 ] of type [Addresses] [Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/Addresses/Address Min Occurs: 0, Max Occurs: -1 ] of type [Address] [Start of sequence Min Occurs: 1, Max Occurs: 1 ]
[Element /Person/Addresses/Address/Line1 Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/Line2 Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/City Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/State Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/Country Min Occurs: 1, Max Occurs: 1 ] of type [string]
[Element /Person/Addresses/Address/PostalCode Min Occurs: 0, Max Occurs: 1 ] of type [string]
[End of sequence]
[End of sequence]
[Element /Person/Gender Min Occurs: 0, Max Occurs: 1 ] of type [Gender][Values = MALE, FEMALE, NOT_SPECIFIED]
[Element /Person/Favorite_Fruits Min Occurs: 0, Max Occurs: 3 ] of type [Fruits][Values = Apple, Banana, Mango, Orange, Grapes, Watermelon, Peach, Apricot, Grapefruit]
[Element /Person/SomeThing_really_whacky-by-the-user Min Occurs: 0, Max Occurs: 1 ] of type [string]
[Element /Person/PatternTest Min Occurs: 1, Max Occurs: 1 ] of type [actionCodeType][Pattern(s) = ((Update|Delete))]
Exception in thread "main" java.lang.NullPointerException
at com.sun.codemodel.JVar.annotate(JVar.java:188)
at com.mickoo.xml.xsd2simplexml.GeneratedClass.addElement(GeneratedClass.java:62)
at com.mickoo.xml.xsd2simplexml.SchemaParser.addSimpleType(SchemaParser.java:276)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processElement(SchemaParser.java:348)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processParticle(SchemaParser.java:208)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processGroup(SchemaParser.java:219)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processParticle(SchemaParser.java:204)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processComplexType(SchemaParser.java:232)
at com.mickoo.xml.xsd2simplexml.SchemaParser.processElement(SchemaParser.java:344)
at com.mickoo.xml.xsd2simplexml.SchemaParser.parse(SchemaParser.java:67)
at com.mickoo.xml.xsd2simplexml.Main.main(Main.java:80)
It looks like it's parsing the XSD file correctly but maybe something is not being configured for the call to JVar.annotate. I'm trying to figure it out but I'm still a bit of a novice with Java.
Have you had any success with working with patterns, or maybe you haven't had a need to do a lot of testing with them? Hopefully it won't take too much of your time to help me with these patterns.
Anyway, thank you very much for a fabulous tool, it is very much appreciated.
Cheers from Down Under,
Tony
The text was updated successfully, but these errors were encountered: