简体   繁体   中英

placing xmlns:xsi into my schema using java

I have the following bit of code

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

The issue is when i run the code i dont get the following created xmlns:xsi after EMOtable1 like:

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

I dont exactly know what the xmlns:xsi means, and then further to this how do i get this inserted?

I am using javax library

This is what is currently written

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

@wero

You first create the namespaced element:

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

and then add the second namespace declaration

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM