版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/coderALEX/article/details/84304026
对于如下XML 元素,要为其添加命名空间和noNamespaceSchemaLocation属性
<Telegram xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Telegram.xsd">
</Telegram>
添加命名空间:
Namespace xsi = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$ //$NON-NLS-2$
Element telegram = new Element("Telegram"); //$NON-NLS-1$
telegram.addNamespaceDeclaration(xsi);
添加noNamespaceSchemaLocation属性:
telegram.setAttribute("noNamespaceSchemaLocation", "Telegram.xsd", xsi);