Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

dom4j / default attributes?  RSS feed

Clarence Schabe
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently using dom4j to parse an xml document. The problem is - in my xml schema (.xsd) file I am specifying a default value for an attribute i.e.:
<xs:attribute name="attr01" type="xs:string" default="some value"/>
Then in my .xml which is based on the .xsd i.e.:
<foo attr01="why does the one below not default to 'some value'">
<bar>This foo has an attr01 set</bar>
<bar>This foo has no attr01, why doesn't it get the default?</bar>
When I parse this .xml in dom4j iterating thru the attributes of the foo elements - it doesn't give me the default value in the second foo element.
I think I can understand this as dom4j doesn't seem to be tied to the schema really.
So the question is how can I parse an .xml doc and retain default values that were specified in schemas for certain attributes? I would like to use dom4j to do this, but I would be open to others. (BTW, I have already successfully done it with jaxb - but I don't think I want to use that method due to other constraints of my application).
Many Thanks!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!