tags:

views:

413

answers:

1

I have an XML that looks like this and a corresponding xsd with it.

<books>
  <book name="book1" id="book1">
    <name>Harry Potter</name>
  ...........
  </book>
  ...........
</books>

Please see that 'name' is appearing twice, once as an attribute in tag, and also as an element under tag. Apparently that is invalid syntax, I am not sure.

When I am trying to generate java classes for this using xjc command (of JAXB), it compains about the invalid duplicate entry in xsd file.

But, I am able to generate C# classes for the xsd using, xsd command in VS 2008.

I have three questions.

  1. Is that XML syntax wrong?

  2. Why is it that xjc(of JAXB) reports error while xsd(of VS2008) does not?

  3. Is there any way I can get xjc(of JAXB) to generate classes (without me having to alter the XML/XSD file) ?

I don't want to alter XML/XSD file as it is 20,000 line file. But that is the last option for me.

+1  A: 
  1. The schema isn't wrong, but it is poorly designed. Using the same name for an attribute and a child element is confusing, although it is legal.
  2. Because they're different tools that generate code for different languages.
  3. XJC can make use of "binding customizations" which allow you to influence how it generates the code. This includes the ability to change the generated java name for any given schema element. This is documented in the JAXB tutorial (see chapter 5, specifically 5.3)
skaffman
@ChanLFC - see the -b comand line switch for using the binding customizations skaffman mentions.
McDowell