Java:如何从DOM元素中删除xmlns?

时间:2017-11-23 15:12:24

标签: java xml dom w3c

同事,找不到我的问题的决定......

这是我的代码,它将SngtrSt元素添加到Envlp

SupplementaryDataEnvelope1 supplementaryDataEnvelope1 = new SupplementaryDataEnvelope1();
//Adding SplmtryData
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.newDocument();
//doc.setDocumentURI("urn:iso:std:iso:20022:tech:xsd:camt.060.001.03");
Element sngtrStElement = doc.createElement("SngtrSt");
sngtrStElement.setTextContent(TranConstants.SNGTR_ST_VALUE);
//sngtrStElement.removeAttributeNS("urn:iso:std:iso:20022:tech:xsd:camt.060.001.03", "xmlns");
supplementaryDataEnvelope1.setAny(sngtrStElement);

结果是:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.060.001.03">
    <AcctRptgReq>
          ...
            <SplmtryData>
                <Envlp>
                    <SngtrSt xmlns="" xmlns:ns2="urn:iso:std:iso:20022:tech:xsd:camt.060.001.03">  </SngtrSt>
                </Envlp>
            </SplmtryData>
    </AcctRptgReq>
</Document>

如何避免将字符串xmlns="" xmlns:ns2="urn:iso:std:iso:20022:tech:xsd:camt.060.001.03"添加到SngtrSt元素(从元素中删除xmlns及其值)?

0 个答案:

没有答案