1
我正在實現一個當前處理JSON並需要處理XML的RESTful Web服務。我使用Jackson來自動將Java對象與JSON進行編組。對於XML,我需要定義一個Schema,主要是因爲客戶需要它。幸運的是,我可以將Schema交給JAXB,而不必編碼自己的XML編碼。開放式XML的模式
一個功能是客戶端可以在實體上設置「自定義屬性」。這些被存儲但不被服務器解釋;他們是爲了客戶端程序的方便。實施例在JSON:
{"id":"abcde",
"customProperties":{
"foo":"bar", "rating":5,
"ridiculousExample":{"food":["green eggs","ham"],
"innerObject":{"name":"Bill","age":47}}
}
}
據推測在XML這將如下所示:
<whatever>
<id>abcde</id>
<customProperties>
<customProperty>
<foo>bar</foo>
</customProperty>
<customProperty>
<rating>5</rating>
</customProperty>
<customProperty>
<ridiculousExample>
<food>
<foodItem>green eggs</foodItem>
<foodItem>ham</foodItem>
<food>
<innerObject>
<name>Bill</name>
<age>47</age>
</innerObject>
</ridiculousExample>
</customProperty>
</customProperties>
</whatever>
在內部(在Java中)JSON數組只是一個陣列和JSON對象是HashMap中。我們可以通過遵循規則從數組hashmaps的數組中生成XML,從而允許我們在XML和JSON之間轉換這些自定義屬性。
XML Schema中是否有任何方法將某些事情指定到某個特定點並說「從這裏開始,只要它是有效的XML就是開放式的」?