jdom2对于XML Element命名空间的操作:添加noNamespaceSchemaLocation属性

版权声明:本文为博主原创文章,未经博主允许不得转载。 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);

猜你喜欢

转载自blog.csdn.net/coderALEX/article/details/84304026