public Document createDocument() {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" ); Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" ); return document;
}
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" ); Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" ); return document;
}
我主要想问的是这部分怎么创建:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Config.xsd">
Element root = doc.addElement("root");
Namespace ns = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.add(ns);
root.addAttribute("xsi:noNamespaceSchemaLocation", "Config.xsd");