Java 6中的JAXB没有在已编组的XML文件中为正确的名称空间前缀加上前缀 [英] JAXB in java 6 not prefixing the correct namespace prefix in marshalled XML file

查看:66
本文介绍了Java 6中的JAXB没有在已编组的XML文件中为正确的名称空间前缀加上前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个架构,该架构在schema元素中具有以下属性:

I have a schema with following attributes in schema element:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:abc="http://abc.example.com" targetNamespace="http://abc.example.com" elementFormDefault="qualified" attributeFormDefault="unqualified">

我可以编译它并获取Java类.使用这些类,我将数据填充到一个对象中,然后将其编组以获取XML文件.

I could compile it and get java classes. Using these classes, I filled in data in an object and marshalled it to get an XML file.

但是此编组文件中的XML元素没有前缀"abc".

But the XML elements in this marshalled file is not having the prefix "abc".

在编组时,我使用XMLStreamWriter.setPrefix进行了一些调整,我可以得到所有元素都以"abc"为前缀的XML文件.

I tweaked a little using XMLStreamWriter.setPrefix while marshalling, and I could get the XML file with all elements prefixed as "abc".

现在,当我尝试解组同一XML文件时,它会抛出错误:

Now when I try to unmarshall the same XML file, it throws error saying :

[org.xml.sax.SAXParseException:元素"abc:Name"的前缀"abc"未绑定.]

[org.xml.sax.SAXParseException: The prefix "abc" for element "abc:Name" is not bound.]

请帮助我,让JAXB知道abc是正确的前缀.

Please help me in how to let JAXB know that abc is correct prefix.

谢谢 普拉迪普(Pradeep)

Thank You Pradeep

推荐答案

前缀的名称是没有意义的.它所做的就是在名称空间和属于该名称空间的标记之间建立连接.前缀是 abc 还是 namespace01 还是没有前缀,因为使用默认名称空间并不重要.据我所知,您不能在JAXB中强制使用前缀或前缀的特定名称.

The name of the prefix is meaningless. All it does is make a connection between a namespace and the tags that belong to that namespace. Whether the prefix is abc or namespace01 or there is no prefix because the default namespace is used doesn't matter. As far as I know you can't force the usage of a prefix or the specific name of a prefix in JAXB.

这篇关于Java 6中的JAXB没有在已编组的XML文件中为正确的名称空间前缀加上前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆