Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
hemamalini nithyanandam
Ranch Hand
Posts: 51
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
g tsuji
Ranch Hand
Posts: 672
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 672
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic