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

xsd:double parsed as ComplexType #21

Closed
radboudp opened this issue Feb 7, 2020 · 8 comments
Closed

xsd:double parsed as ComplexType #21

radboudp opened this issue Feb 7, 2020 · 8 comments

Comments

@radboudp
Copy link

radboudp commented Feb 7, 2020

<xsd:element name = 'hoursPerWeek' minOccurs='0' maxOccurs='1' type='xsd:double'> <xsd:annotation> <xsd:documentation xml:lang="en"> <ccts:DictionaryEntryName>F8C43CF9-9218-E611-80EA-000C292ED0D7</ccts:DictionaryEntryName> </xsd:documentation> </xsd:annotation> </xsd:element>

Above xsd:double inside a sequence inside a global named complexType is identified as an complexType.

image

@lcduarte
Copy link
Member

lcduarte commented Feb 8, 2020

Hi,

This is the default behaviour for types of XSD that have representation in the Java language. This list is defined in getXsdTypesToJava of ParserConfig. This means that if any element has an attribute type with one of the values defined in this method a XsdComplexType will be created to represent the respective xsd type.

This aims to stardardize the way the type attribute usually refers to another xsd:complexType or xsd:simpleType.

If you want to access the value of the type attribute you can always use:

currentElement.getAttributesMap().get("type");
//Or as of 1.0.25
currentElement.getAttributesMap().get(XsdAbstractElement.TYPE_TAG); 

Hope this helped!

@radboudp
Copy link
Author

radboudp commented Feb 9, 2020

I find this counter intuitive in respect to when the a type attribute refers to an actual complextype or an actual simple type. Actually a type that refers to an xsd base type might require a class if itself.

It is most definitely not a complextype.

@lcduarte
Copy link
Member

lcduarte commented Feb 9, 2020

I get your point. I added another type XsdBuiltInDataType to represent the built in Xsd types, which can be configured in the configuration of the parser if for some reason the default configuration is missing something you need.

It still works the same way if the type attribute refers a xsd:complexType or a xsd:simpleType element but if it refers a type configured as a built in xsd type it maps it to a XsdBuiltInDataType instance.

There are also four new methods in XsdElement to reflect this change:

public XsdNamedElements getTypeAsXsd();
public XsdComplexType getTypeAsComplexType();
public XsdSimpleType getTypeAsSimpleType();
public XsdBuiltInDataType getTypeAsBuiltInDataType();

The new release is published with these changes - 1.0.27.

@radboudp
Copy link
Author

radboudp commented Feb 9, 2020

Hi Luis,

Many thanks, What prompted you to create this library?

Let me explain to what we are doing. We have created a generic forms backend for outgoing correspondence. It provides logic like multiple versions of the correspondence filled out, allowing users to save draft en final versions, rollback, continue old versions, commit, release for sending. The correspondence is filled out with data collected in a form. This data and form are generic and is managed by an XSD. So a correspondence received by this backend is accompanied by a type, which is linked to an XSD. The XSD is used to translate de JSON data (no ordering required) to XML, respecting the ordering of the XSD. Also we validate the form data against the XSD. We noticed that regular validation lacks in reporting a number of problems. For example, it reports for instance an error "unexpected field" in stead of errors on missing required fields.

Your library comes in to analyse the XSD and extract information about each allowed item in the XSD. We put all that information in a map, with the XPATH to the element as key for easy, quick access. We collect the following information per element:

  • is it a simple type?
  • is it a complex type?
  • if it is simple, is it nummeric, boolean, binary or other?
  • What are the allowed sub elements? (in order as in the XSD).
  • What are the required sub elements?
  • Which sets of choice elements are present?

We could have collected the information directly parsing the XSD DOM strucure, but your library made it a lot easier! Many thanks!

Currently we use underscore library to translate the JSON to XML. For XML to JSON we use SAX2J library found on github. I am thinking about using your library to build our own JSON to XML and XML to JSON library with knowledge of the XSD. Problem at converting JSON to XML and vice versa is knowing if something should be an array in JSON (thus allowed multiple times). From analyzing the XML alone, you can only see this when an element is present multiple times. Therefor the underscore library adds all sorts of attributes to the XML, preventing a validation against the XSD, but allowing reverse conversion. When the XSD allowed into the conversion, then these attributes are not necessary.

Keep up the good work on your library!

@lcduarte
Copy link
Member

lcduarte commented Feb 9, 2020

Thanks for the message, it's always nice to know how our code is helping other people!

This library started as a means to an end. In my master thesis I needed to convert a XSD definition into a fluent Java API. In order to do that I needed a tool to properly map the whole XSD language to Java so I could extract all the required information about the XSD definition in order to create an API that best reflects the XSD that was being used.

The use case was the HTML language, with the respective XSD definition. That ultimately resulted in the HtmlFlow library which uses the HtmlApiFaster API which was generated based on the information extracted by this library.

In that context this library has stagnated since it already does what was required, but I still mantain it to help other developers use it in order to solve their problems.

Feel free to keep posting issues, I may not respond during the week but usually on the weekends I'll check it out.

@fmcarvalho
Copy link
Member

@radboudp We are always curious about applications of our libraries and I found very interesting your use case and the use of XSD. Can you explain a little bit more about the XML need? What is the end goal of having data in XML format?

Thank you,
Miguel

@radboudp
Copy link
Author

radboudp commented Feb 11, 2020 via email

@fmcarvalho
Copy link
Member

@radboudp Can you send me an email to talk a little bit more about that system privately?

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

No branches or pull requests

3 participants