How to get JAXB output to have namespace included with the child node with no prefix?

冷暖自知 提交于 2019-12-02 15:17:53

问题


God knows I searched the forum for an answer, but didn't see any. This is the simplified XML my JAXB code reads. There are 2 namespaces involved. xyz and abc. These two are defined in two different schema files. And xjc generates two different packages for them. The following file is nicely read into those classes and can even write it.

<xyz:xyz xsi:schemaLocation="urn:xyz xyz.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xyz="urn:xyz">
    <session>
        <App xsi:schemaLocation="urn:abc abc.xsd" xmlns="urn:abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <AppItem att1="1234"/>
        </App>
    </session>
</xyz:xyz>

This is how it writes it.

<ns3:xyz xmlns:ns2="urn:abc" xmlns:ns3="urn:xyz">
    <session>
        <ns2:App>
            <ns2:AppItem att1="1234"/>
        </ns2:App>
    </session>
</ns3:xyz>

Now i know about NamespacePrefixMapper and I can change ns2 and ns3 to the values I want. And I want this. Basically I want to main the original form of the XML. The App element should have all its information contained in itself and not create a prefix.

<xyz:xyz xmlns:xyz="urn:xyz">
    <session>
        <App xsi:schemaLocation="urn:abc abc.xsd" xmlns="urn:abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <AppItem att1="1234"/>
        </App>
    </session>
</xyz:xyz>

Does anyone have any clue as to how to achieve this? Seems like some setting in AppType.java should tell the writer to not update root element with prefix.

来源:https://stackoverflow.com/questions/8057733/how-to-get-jaxb-output-to-have-namespace-included-with-the-child-node-with-no-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!