• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 53
Eclipse IDE MySQL Database Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 53
Eclipse IDE MySQL Database Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic