1

使用 javax.xml.Transform 在转换后的 xml 文件中包含 xml:base 属性。这是场景。

示例 XML 文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE security [
<!ENTITY attachparam SYSTEM "attach-value.xml">
<!ENTITY udf SYSTEM "udfasset.xml">
]>
<property>
           &attachparam;

</property>    

附加值.xml

<value regex=".+">localhost</value>
<value regex="^[A-Z]+">allow</value>

输出:

<?xml version="1.0" encoding="UTF-8" standalone="no">
<property> 
     <value regex=".+" xml:base="file:///home/bharathi/attach-value.xml">localhost</value>    
     <value regex="^[A-Z]+" xml:base="file:///home/bharathi/attach-value.xml">allow</value>    
</property>

Java 代码:

               TransformerFactory transformerFactory = TransformerFactory.newInstance();
                Transformer transformer = transformerFactory.newTransformer();

                DOMSource source = new DOMSource(document);

                String tempFile = "/home/bharathi/out.xml";
                LOGGER.log(Level.INFO, "tempFile is :: " + tempFile);

                StreamResult result = new StreamResult(new File(tempFile));

                transformer.transform(source, result);

转换时如何排除 xml:base 属性?

4

0 回答 0