我嘗試生成一些包含架構的xml文件。我使用jaxb從架構中創建xml文件,但是我無法在此xml.My中添加架構文件看起來像在java中使用xml架構創建xml文件
<transaction>
<xs:schema id="transaction" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="transaction" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="id">
<xs:complexType>
<xs:sequence>
<xs:element name="in" type="xs:string" minOccurs="0" />
<xs:element name="sn" type="xs:string" minOccurs="0" />
<xs:element name="book" type="xs:string" minOccurs="0" />
<xs:element name="author" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="key" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="productData">
<xs:complexType>
<xs:sequence>
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="key" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<id>
<in>abcd</in>
<sn>1234567</sn>
<book>computer</book>
<author>klen</author>
</id>
<data>
<dateTime>2011-06-24T17:08:36.3727674+05:30</dateTime>
<key>Err</key>
</data>
</transaction>
,但到現在爲止,我能夠生成xml文件看起來像
<transaction>
<id>
<in>abcd</in>
<sn>1234567</sn>
<book>computer</book>
<author>klen</author>
</id>
<data>
<dateTime>2011-06-24T17:08:36.3727674+05:30</dateTime>
<key>Err</key>
</data>
</transaction>
我不知道如何下node.is有什麼辦法可以添加此架構添加此模式在節點下使用java.maain中的jaxb我的部分代碼就像
transaction.getIdOrDataOrProductData().add(id);
transaction.getIdOrDataOrProductData().add(data);
transaction.getIdOrDataOrProductData().add(productdata);
JAXBContext jaxbContext = JAXBContext.newInstance(Transaction.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT,true);
jaxbMarshaller.marshal(transaction, file);
jaxbMarshaller.marshal(transaction, System.out);
是否有任何方法來改變我可以添加模式與XML文件的代碼。
我們的應用程序實際上檢查文件結構,如果它看起來不像我給出的例子那麼它將被刪除,所以我應該遵循這個結構,它將更新數據庫。現在我的問題是,我該如何添加這個我的使用jaxb的xml文件。
使用C#.NET平臺它可以生成xml文件與schema.is它可能在java中。
@Patrice Matignon你能告訴我如何發送這個模式對象,以及編組我可以使用模式生成xml文件的模式。 – saba 2012-03-28 18:47:16
@Patrice Matignon對不起,我不清楚你能不能簡單地描述它其實我是java中的新手,所以我無法理解你的建議。其實我沒有改變我的模式,另一件事是我如何轉換將xslt轉換爲帶模式的xml。 – saba 2012-03-30 04:12:36