It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes dom4j / default attributes? 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 "dom4j / default attributes?" Watch "dom4j / default attributes?" New topic

dom4j / default attributes?

Clarence Schabe

Joined: May 12, 2004
Posts: 5
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!
I agree. Here's the link:
subject: dom4j / default attributes?
It's not a secret anymore!