如何在 Java 包信息中复制 NamespaceURI 声明

How to duplicate NamespaceURI declaration in Java package-info

我定义了一个包-info.java class,我需要生成一个 xml 文件,其中包含此处定义的所有 xmlns:

@javax.xml.bind.annotation.XmlSchema(namespace = "dian:gov:co:facturaelectronica:NominaIndividual", 
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
        @XmlNs(prefix = "", namespaceURI = "dian:gov:co:facturaelectronica:NominaIndividual"),
        @XmlNs(prefix = "ds", namespaceURI = "http://www.w3.org/2000/09/xmldsig#"),
        @XmlNs(prefix = "ext", namespaceURI = "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"),
        @XmlNs(prefix = "cbc", namespaceURI = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"),
        @XmlNs(prefix = "cac", namespaceURI = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"),
        @XmlNs(prefix = "xades", namespaceURI = "http://uri.etsi.org/01903/v1.3.2#"),
        @XmlNs(prefix = "xades141", namespaceURI = "http://uri.etsi.org/01903/v1.4.1#"),
        @XmlNs(prefix = "xs",  namespaceURI = "http://www.w3.org/2001/XMLSchema-instance"),
        @XmlNs(prefix = "xsi", namespaceURI = "http://www.w3.org/2001/XMLSchema-instance")})
        
package com.sifactura.nomina.imports.dian.gov.co.facturaelectronica.nominaindividual;

import javax.xml.bind.annotation.XmlNs;

在结果 xml 中,删除了前缀 xs。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<NominaIndividual SchemaLocation="" 
    xmlns="dian:gov:co:facturaelectronica:NominaIndividual" 
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" 
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" 
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
    xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" 
    xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" 
    xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="dian:gov:co:facturaelectronica:NominaIndividual NominaIndividualElectronicaXSD.xsd">

我假设因为 namespaceURI 被定义了两次,但我需要两个命名空间。有任何配置来定义所有 XmlNs 前缀吗?

编辑:21/03/2022 我最终以编程方式添加了该命名空间:

Node nodeNs = document.getDocumentElement();
        ((Element)nodeNs).setAttributeNS("http://www.w3.org/2000/xmlns/",
                   "xmlns:xs", "http://www.w3.org/2001/XMLSchema-instance");

编辑:21/03/2022 我最终以编程方式添加了带有

的命名空间
Node nodeNs = document.getDocumentElement();
((Element)nodeNs).setAttributeNS("http://www.w3.org/2000/xmlns/",
               "xmlns:xs", "http://www.w3.org/2001/XMLSchema-instance");