簡體   English   中英

具有指定模式的JAXB Marshaller

[英]JAXB Marshaller with specified schema

我想在我編組的每個xml文件中定義模式。 然后在解組過程中獲取此模式(路徑字符串)。 僅限marshaller.setSchema()

允許調用者在編組時驗證編組的XML。

是的,我可以為此目的編寫額外的bean,但我希望得到xml之類的

<root
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation='bla-bla.xsd'>...

要指定noNamespaceSchemaLocation,您可以執行以下操作:

JAXBContext jc = JAXBContext.newInstance(Root.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "bla-bla.xsd");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM