我不太明白你的问题。
我觉得你的XSD会给你的Java类生成XML这样的:
<book author="Fred" title="The Lady and a Little Dog" />
你的意思是你想设置的XML元素中的“内部”的文字,所以你最终与XML一样这个?
<book>
<author>Fred</author>
<title>The Lady and a Little Dog</title>
</book>
如果是这样,你的XSD改变这一点,使用嵌套元素,而不是属性:
<xs:sequence>
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element name="author" type="xs:string" />
<xs:element name="title" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
然后你就只是能够做到:
Book book= books.addNewBook();
book.setAuthor("Fred");
book.setTitle("The Lady and a Little Dog");
UPDATE
好的 - 我现在明白了。
试试这个:
<xs:element name="Book" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="author" type="xs:string" />
<xs:attribute name="title" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
然后:
Book book1 = books.addNewBook();
book1.setAuthor("Fred");
book1.setTitle("The Lady and a Little Dog");
book1.setStringValue("This is some text");
Book book2 = books.addNewBook();
book2.setAuthor("Jack");
book2.setTitle("The Man and a Little Cat");
book2.setStringValue("This is some more text");
应该给这样的XML,我认为这是你想要什么:
<Book author="Fred" title="The Lady and a Little Dog">This is some text</Book>
<Book author="Jack" title="The Man and a Little Cat">This is some more text</Book>
这是我会像我的xml看起来像:这是一些文字 我怎样才能把”这是一些文字“位? 谢谢 –
dogbane
2009-05-20 12:10:04