java xml 空节点_使用DocumentBuilderFactory进行Java XML解析-空节点?

这篇博客详细介绍了在Java中如何使用DOM解析器来获取XML文档中元素的本地名称和标签名。通过调用`getLocalName()`和`getTagName()`方法,可以分别得到元素的局部名称(在命名空间中)和完整的标签名。文章强调了这两个方法在处理DOM节点时的区别,并指出在HTML文档中,`getTagName()`通常返回大写的标签名。
摘要由CSDN通过智能技术生成

您想要标签名称吗?使用rootElement.getTagName();

从Java文档中:

公共字符串getLocalName()

Returns the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as Document.createElement(), this is always null. Since: DOM Level 2.

公共字符串getTagName()

The name of the element. If Node.localName is different from null, this attribute is a qualified name. For example, in:

...

,

tagName has the value “elementExample”. Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值