使用 Java 将 XMLNS:XSI 放入我的模式中



我有以下代码

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element rootElement = document.createElementNS("http://www.w3.org/2001/XMLSchema-instance", xmlns="http://www.europe.xsd","EMOTable1");//create the rootelement
document.appendChild(rootElement);//append the root element to the doc

问题是当我运行代码时,我在 EMOtable1 之后没有得到以下创建的 xmlns:xsi,例如:

<EMOTable1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.europe.xsd">

我不完全知道 xmlns:xsi 是什么意思,然后进一步说明如何插入它?

我正在使用javax库

这是目前写的

<EMOTABLE1 xmlns="http://www.w3.org/2001/XMLSchema-instance&quot;xmlns=&quot;http://www.europe.xsd">

@wero

首先创建命名空间元素:

Element rootElement = doc.createElementNS("http://www.europe.xsd", "EMOTable1");

然后添加第二个命名空间声明

rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");

最新更新