Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 从JAXB模式位置删除模式实例_Xml_Jaxb - Fatal编程技术网

Xml 从JAXB模式位置删除模式实例

Xml 从JAXB模式位置删除模式实例,xml,jaxb,Xml,Jaxb,如果有人知道如何使用Jaxb技术,请来到这里寻求帮助。我希望使用Marshaller.JAXB_SCHEMA_位置生成XML,这样可以创建类似这样的内容 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xsi:schemaLocation=“Document.xsd” 我想省略这个xsi:schemaLocation=“Document.xsd”元素, 到目前为止,我还没有找到任何解决方案,也没有提到任何类似的情况,如何编辑这个生成的标签

如果有人知道如何使用Jaxb技术,请来到这里寻求帮助。我希望使用Marshaller.JAXB_SCHEMA_位置生成XML,这样可以创建类似这样的内容

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xsi:schemaLocation=“Document.xsd”

我想省略这个xsi:schemaLocation=“Document.xsd”元素, 到目前为止,我还没有找到任何解决方案,也没有提到任何类似的情况,如何编辑这个生成的标签。这里有人知道怎么做吗?非常感谢你的帮助


Cheers

设置
Marshaller.JAXB_SCHEMA_LOCATION
属性的唯一原因是将其显示在编组的XML中。如果不希望它出现,则不需要设置该属性


更新
因为我有一些规范,说明了 xsi:schemaLocation=“Document.xsd”无法显示,因此必须显示最终标记 看起来像到目前为止还没有 成功

基于此评论,我相信您正在寻找有关如何对模型进行名称空间限定的信息。下面是一个例子

Java模型 套餐信息

@XmlSchema(
namespace=“urn:iso:std:iso:20022:tech:xsd:pain.001.001.03”,
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns={
@XmlNs(prefix=”“,namespaceURI=“urn:iso:std:iso:20022:tech:xsd:pain.001.001.03”),
@XmlNs(prefix=“xsi”,namespaceURI=”http://www.w3.org/2001/XMLSchema-instance")
}
)
20397718包;
导入javax.xml.bind.annotation.*;
文档

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
用于UM20397718的包;
导入javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name=“Document”)
公共类文档{
}
演示代码 演示

用于UM20397718的包;
导入javax.xml.bind.*;
公开课演示{
公共静态void main(字符串[]args)引发异常{
JAXBContext jc=JAXBContext.newInstance(Document.class);
文档=新文档();
Marshaller=jc.createMarshaller();
setProperty(marshaller.JAXB_格式化的_输出,true);
封送员。封送员(文件、系统、输出);
}
}
输出

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

更多信息

  • 你的问题把我弄糊涂了。您说您使用适当的
    Marshaller
    属性添加schemaLocation,然后询问如何删除它。你们想得到什么结果?嗨,marshaller和jaxb_schema_位置生成完整的模式,如上所述,但我想要的是从中删除**xsi:schemaLocation=“Document.xsd”**元素,到目前为止我还没有找到任何方法使其达到所需状态,谢谢你们的帮助嗨,是的,理解,但我有一些具体的情况,当我需要没有xsi:schemaLocation=“Document.xsd”属性的属性时,而这是我无法实现的。@user3069432-如果您不想编写它,为什么要设置该属性?因为我有一些规范,该属性xsi:schemaLocation=“Document.xsd”无法显示,因此最终标记必须看起来像迄今为止没有任何success@user3069432-我已经用一些可能有用的信息更新了我的答案。您好,谢谢,在我看来这是一个很好的解决方案,但我还考虑到属性xsi:schemaLocation=“Document.xsd”可以从根标记中删除org.w3c.dom中的一些方法吗?我发现etc.从元素类中删除了属性(字符串arg0,字符串arg1),但不知道在该方法中可以填充哪些参数。