Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime and Restrictions #7

Closed
yeshodhan opened this issue Jan 8, 2016 · 1 comment
Closed

DateTime and Restrictions #7

yeshodhan opened this issue Jan 8, 2016 · 1 comment
Assignees
Labels

Comments

@yeshodhan
Copy link
Owner

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:

    <xs:simpleType name="actionCodeType">
        <xs:restriction base="xs:string">
            <xs:pattern value="(Update|Delete)" />
        </xs:restriction>
    </xs:simpleType>

​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

@yeshodhan yeshodhan self-assigned this Jan 11, 2016
yeshodhan pushed a commit that referenced this issue Jan 11, 2016
@yeshodhan yeshodhan added the bug label Jan 11, 2016
@yeshodhan
Copy link
Owner Author

Hey Tony, Checked in a fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant