aspose file tools*
The moose likes XML and Related Technologies and the fly likes JAXB- how to define XSD for XML with varying elements and parse using JAXB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB- how to define XSD for XML with varying elements and parse using JAXB" Watch "JAXB- how to define XSD for XML with varying elements and parse using JAXB" New topic
Author

JAXB- how to define XSD for XML with varying elements and parse using JAXB

hemamalini nithyanandam
Ranch Hand

Joined: Oct 24, 2011
Posts: 50

I have a xml likethis



I need to define XSD for this XML. I used value as complex type . but when i use value as complex type i am not able to parse the string value from Value in JAXB. I am getting a object only. If i declare value as simple type(String) i am not able to read the filename.what should i do..please help.


have a nice day - hema
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 517
    
    3
The schema 1.0 of w3c may not be expressive enough to fulfill seemingly an implicit condition that you've in mind, namely, if it has a non-whitespace text child (like "some string" in the first two datapoint), the element filename must be absent and conversely if filename element is present there must not be any non-whitespace non-negligible text node as its sibling. The best the schema can do is this.

You can still use it for code generation, though.
hemamalini nithyanandam
Ranch Hand

Joined: Oct 24, 2011
Posts: 50

I am using JAXB parser. i changed the schema as per your suggestion. Now i am able to read only normal string. I am not able to read the content inside the file name.. Do i have to use two XSD?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 517
    
    3
Do i have to use two XSD?

No. But as an aside, to use two xsd? in what sense?

Now i am able to read only normal string. I am not able to read the content inside the file name..

There may not be only one way to read correctly everything, but there sure are many ways to not be able to read the content inside the file name... If you want help, show a scaled down sample of how you do it. The xsd component I posted is capable of validating the value element for sure: only it is allowing slight more structure than your sample xml care to show - but sample is a sample, it is not supposed to be exhaustive or tacitly disallow everything not appeared in the sample. If you stick to your sample xml, it certainly won't blow up.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JAXB- how to define XSD for XML with varying elements and parse using JAXB