这是使用QDomDocument声明命名空间的正确方法吗?
QDomDocument doc;
// Header
doc.appendChild( doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"") );
QDomElement project = doc.createElement( "cnsc:projectConfiguration" );
project.setAttribute( "xmlns:cnsc", "cnsConfiguration" );
project.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
project.setAttribute( "xsi:schemaLocation", "cnsConfiguration http://simsert-doc.obs.ujf-grenoble.fr/xsd/cnsConfiguration.xsd");
doc.appendChild( project );
给我:
<?xml version="1.0" encoding="utf-8"?>
<cnsc:projectConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" :schemaLocation="cnsConfiguration http://simsert-doc.obs.ujf-grenoble.fr/xsd/cnsConfiguration.xsd" xmlns:cnsc="cnsConfiguration"/>
或者这样:
QDomDocument doc;
// Header
doc.appendChild( doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"") );
QDomElement project = doc.createElementNS( "cnsConfiguration", "cnsc:projectConfiguration" );
project.setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance" , "xsi:schemaLocation" , "cnsConfiguration http://simsert-doc.obs.ujf-grenoble.fr/xsd/cnsConfiguration.xsd");
我能给我:
<?xml version="1.0" encoding="utf-8"?>
<cnsc:projectConfiguration xmlns:cnsc="cnsConfiguration" xsi:schemaLocation="cnsConfiguration http://simsert-doc.obs.ujf-grenoble.fr/xsd/cnsConfiguration.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">