如何创建属性“xsi:type”在java中使用DOM? [英] How to create an attribute "xsi:type" using DOM in java?

查看:115
本文介绍了如何创建属性“xsi:type”在java中使用DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在尝试创建一个属性并将其值设置为,

Hello,

I am trying to create an attribute and set its value as,

newElement = doc.createElement("SHORT-NAME");
newElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema");
attribute = doc.createAttribute("xsi:type");
attribute.setValue("VALUE");
newElement.setAttributeNode(attribute);









这里我希望输出为,





Here I am expecting the output as,

<SHORT-NAME xsi:type = "VALUE">





但是我得到了输出,< br $> b $ b



But I am getting the output,

<SHORT-NAME xmlns:xsi = "http://www.w3.org/2001/XMLSchema" xsi:type = "VALUE>"





但是我必须为我的属性提供命名空间。



如何设置命名空间属性并获得我的预期结果?



But here it is mandatory that I should provide a namespace for my attribute.

How to set the namespace attribute and get my expected result ?

推荐答案

怎么样



how about

newElement = doc.createElement("SHORT-NAME");
attribute = doc.createAttribute("xsi:type");
attribute.setValue("VALUE");
newElement.setAttributeNode(attribute);





有效吗?



does that work?


这篇关于如何创建属性“xsi:type”在java中使用DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆