编程语言
首页 > 编程语言> > java-使用apache xmlbeans将名称空间定义添加到xml

java-使用apache xmlbeans将名称空间定义添加到xml

作者:互联网

我需要为元素添加名称空间定义,因为使用apache xmlbean生成xml时不会添加元素.如何使用xmlbeans API做到这一点?

解决方法:

我已经找到问题的答案.
就是这样.

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

标签:xmlbeans,xml,java
来源: https://codeday.me/bug/20191210/2098498.html