在元素上设置命名空间属性 [英] Setting Namespace Attributes on an Element

查看:29
本文介绍了在元素上设置命名空间属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Java 创建一个包含以下元素的 XML 文档:

I'm trying to create an XML document in Java that contains the following Element:

<project xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2" 
         xmlns:acme="http://www.acme.com/schemas"
         color="blue">

我知道如何创建项目 Node.js.我也知道如何使用

I know how to create the project Node. I also know how to set the color attribute using

element.setAttribute("颜色","蓝色")

我是使用 setAttribute() 以相同的方式设置 xmlns 和 xmlns:acme 属性,还是因为它们是命名空间属性而以某种特殊方式进行设置?

Do I set the xmlns and xmlns:acme attributes the same way using setAttribute() or do I do it in some special way since they are namespace attributes?

推荐答案

相信你一定要用到:

element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:acme", "http://www.acme.com/schemas");

这篇关于在元素上设置命名空间属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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