Adding namespace definition to xml using apache xmlbeans

丶灬走出姿态 提交于 2019-12-01 00:00:06
nobody

I have found answer to the problem. Here's how it is.

XmlCursor cursor= targetObject.newCursor();
cursor.toNextToken();
cursor.insertNamespace("A", "namespace1");
//For example
cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
cursor.dispose();
pranav

Use:

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!