我正在尝试构建一个包含许多属性的XML文档。但是,代码会继续为元素本身添加前缀,并添加d1p1并破坏我的所有属性。
这是我到目前为止所拥有的:
String str = "1 */ * / 2";
Pattern p = Pattern.compile("\\*/");
Matcher m = p.matcher(str);
while(m.find()){
String match = m.group();
//do something with match
System.out.println(match);
}
输出是这样的:
var doc = new XmlDocument();
var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(declaration);
var xmlns = "http://www.kuju.com/TnT/2003/Delta";
var root = doc.CreateElement("d", "cCSvArray", xmlns);
root.SetAttribute("d", "version", "1.0");
root.SetAttribute("d", "id", "1");
doc.AppendChild(root);
我需要的是这个
<?xml version="1.0" encoding="utf-8"?>
<d:cCSvArray d1p1:d="1.0" d1p2:d="1" xmlns:d1p2="id" xmlns:d1p1="version" xmlns:d="http://www.kuju.com/TnT/2003/Delta" />
我该如何实现?
编辑:最终文档应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<cCSVArray xmlns:d="http://www.kuju.com/TnT/2003/Delta" d:version="1.0" d:id="1"/>
答案 0 :(得分:1)
var doc = new XmlDocument();
var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(declaration);
var xmlns = "http://www.kuju.com/TnT/2003/Delta";
var root = doc.CreateElement("cCSvArray");
root.SetAttribute("xmlns:d", xmlns);
root.SetAttribute("version", xmlns, "1.0");
root.SetAttribute("id", xmlns, "1");
doc.AppendChild(root);