Apache xmlbean を使用して xml を生成するときに追加されないため、要素に名前空間定義を追加する必要があります。xmlbeans API を使用してこれを実現するにはどうすればよいですか?
6241 次
2 に答える
3
私はその問題に対する答えを見つけました。これがその方法です。
XmlCursor cursor= targetObject.newCursor();
cursor.toNextToken();
cursor.insertNamespace("A", "namespace1");
//For example
cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
cursor.dispose();
于 2010-06-16T08:54:43.713 に答える
0
使用する:
XmlOptions.setSaveSuggestedPrefixes()
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
xmlOptions.setSavePrettyPrintIndent(4);
xmlOptions.setSaveAggressiveNamespaces();
HashMap<String, String> nsMap = new HashMap<String, String>();
nsMap.put("namespace1","A");
nsMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
xmlOptions.setSaveSuggestedPrefixes(nsMap);
// Create your XmlObject
<Your XmlObject>.save(new File("test.xml"),xmlOptions);
于 2013-03-29T09:01:47.233 に答える