xsi:schemaLocation 使用 org.w3c 具有多个值
xsi:schemaLocation with multiple values using org.w3c
我正在尝试将多个值附加到 schemaLocation 属性:
Document document = null;
Element documentElement = null;
final DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
Element root = null;
try {
final DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
root = document.createElement("kml");
document.appendChild(root);
documentElement = document.createElement("Document");
final Element topNameElement = document.createElement("name");
documentElement.appendChild(topNameElement);
root.appendChild(documentElement);
root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xmlns", "http://schemas.opengis.net/kml/2.2.0");
root.setAttribute("xmlns:ar", "http://schemas.opengis.net/arml/2.0");
root.setAttribute("xsi:schemaLocation", "http://schemas.opengis.net/kml/2.2.0 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://schemas.opengis.net/arml/2.0 http://schemas.opengis.net/arml/2.0/arml.xsd");
然而,结果是:
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://schemas.opengis.net/kml/2.2.0" xmlns:ar="http://schemas.opengis.net/arml/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.opengis.net/kml/2.2.0 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd 	http://schemas.opengis.net/arml/2.0 	http://schemas.opengis.net/arml/2.0/arml.xsd">
<kml>
</kml>
我如何添加多个值来移除编码?
是白色space 字符。在您的代码中,您在 schemaLocation 条目之间使用了额外的 whitespace 。每次尝试将其减少到一个 space。
我正在尝试将多个值附加到 schemaLocation 属性:
Document document = null;
Element documentElement = null;
final DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
Element root = null;
try {
final DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
root = document.createElement("kml");
document.appendChild(root);
documentElement = document.createElement("Document");
final Element topNameElement = document.createElement("name");
documentElement.appendChild(topNameElement);
root.appendChild(documentElement);
root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xmlns", "http://schemas.opengis.net/kml/2.2.0");
root.setAttribute("xmlns:ar", "http://schemas.opengis.net/arml/2.0");
root.setAttribute("xsi:schemaLocation", "http://schemas.opengis.net/kml/2.2.0 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://schemas.opengis.net/arml/2.0 http://schemas.opengis.net/arml/2.0/arml.xsd");
然而,结果是:
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://schemas.opengis.net/kml/2.2.0" xmlns:ar="http://schemas.opengis.net/arml/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.opengis.net/kml/2.2.0 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd 	http://schemas.opengis.net/arml/2.0 	http://schemas.opengis.net/arml/2.0/arml.xsd">
<kml>
</kml>
我如何添加多个值来移除编码?
是白色space 字符。在您的代码中,您在 schemaLocation 条目之间使用了额外的 whitespace 。每次尝试将其减少到一个 space。