2
我正在努力解決如何解組並將XML文檔解析爲Java文檔。 的XML文檔的頂部看起來像這樣Spring JAXB - 使用模式驗證解組XML文檔
<xs:myData xmlns:xs="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com example.xsd ">
有一個schema文件,其頂部是這樣的:
<schema targetNamespace="http://www.example.com"
elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.example.com">
我想解組使用Spring/JAXB並最終XML文檔將其轉換爲JPA對象。我不知道如何去,所以我尋找谷歌的例子,並提出了這個http://thoughtforge.net/610/marshalling-xml-with-spring-ws-and-jaxb/
我瞭解它的大部分,除了如何或在哪裏架構使用。
我看到其中的模式是明確指出其它實例中,即
SchemaFactory schemaFac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema sysConfigSchema = schemaFac.newSchema(
new File("example.xsd"));
unmarshaller.setSchema(sysConfigSchema);
RootElement root = (RootElement)unmarshaller.unmarshal(
new File("example1.xml"));
- 在所述第一鏈路中示出的架構如何用來驗證XML文檔?
- 使用Spring的jaxb2Marshaller而不是直接使用JAXB有什麼缺點嗎?
- XmlElement註釋旁邊的命名空間有什麼影響? (請參閱Person類)
我希望有更多的例子顯示Spring/REST帶有解組模式驗證的Spring/REST。
感謝
我的快速回答:(1)從xmlns:xsi引用的XSD未加載/用於驗證XML(2)沒有區別,除非JAXB頂部的spring「sugar」 3)如果有人不使用命名空間,這很少見。 – 2012-02-13 20:48:27
那麼這篇文章中引用的模式是用來做什麼的? – ziggy 2012-02-14 09:06:38
在文章中,Spring上下文引用了您需要明確放入資源的'person.xsd'(' '')。然後,當生成XML時,JAXB編組器將使用此模式來驗證XML。 –
2012-02-14 21:31:16