如何检测空标签?

编程入门 行业动态 更新时间:2024-10-10 23:21:03
本文介绍了如何检测空标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有DOM文档,如何检测空标签? 例如:< br />和< br>< / br> 我试过org.w3c.dom.Node.getFirstChild(),它为两个< br $ b返回null $ b />和< br>< / br> 我也试过getNodeValue(),它们都返回null。 我知道< br /> ;和< br>< / br>从xml规范是相同的。有没有 使用DOM解析器告诉不同的语法? 谢谢, -John

解决方案

2005年4月13日18:23:59 -0700,vega <乔**** @ gmail>写道:

如果我有DOM文件,如何检测空标签? 例如:< br />和< br>< / br>

你不能,你不需要。在XML中,这些正好等于(bic)。 www.w3/TR/2004/REC-xml-20...#sec-starttags 空元素标签可用于任何没有内容的元素, ,无论是否使用关键字EMPTY声明它。对于 互操作性,应该使用empty-element标签,并且只应使用,用于声明为EMPTY的元素。 您可以在DTD或架构的元素' 定义中找到有用的差异 - i..e。 EMPTY你可以通过 解析它,或者(更容易)通过使用文件解析器来访问它, 理解模式并提供更直接的相关链接。 这是定义,而不是实例。它不会告诉你 是否使用了文档中标记的空元素形式因为 它是一个EMPTY元素,或者只是一个非元素-bmp元素碰巧 在这个例子中没有内容。 一般来说,文档被序列化的方式是不可见的 到一个XML应用程序,更重要的是没有理由为什么需要它是。你永远不需要它。 如果你确实认为你需要它,那么很有可能你处于一个非XML的上下文中,例如XHTML或RSS。虽然这些表面上是XML协议,但它们存在于一个仍然根植于 HTML过去的环境中。可能有充分的理由仍然关心纯粹的XML上下文不需要的东西。

<峰; br />和< br>< / br>根据XML规范是一样的。我不认为 任何兼容的XML解析器都会以不同的方式对待这两种方式。所以我认为认为XML解析器无法报告这种差异.. 也好奇,为什么这个信息对于 $ b有用$ b你.. 问候, Mukul " vega" <乔**** @ gmail>在消息新闻中写道:< 11 ******************** @ z14g2000cwz.googlegro ups> ...

我该如何如果我有DOM文件,检测空标签? 例如:< br />和< br>< / br> 我试过org.w3c.dom.Node.getFirstChild(),它为< br />返回null和< br>< / br> 我也试过getNodeValue(),它们都返回null。 我知道< br />和< br>< / br>从xml规范是相同的。是否有任何方法可以使用DOM解析器告诉不同的语法? 谢谢, -John

文章< b1 ************************* @ posting.google> , Mukul Gandhi< mu ********** @ yahoo>写道:

< br />和< br>< / br>根据XML规范是相同的。我不认为任何兼容的XML解析器会以不同的方式对待这两种方式。所以我认为XML解析器无法报告这种差异.. XML解析器可以报告它喜欢什么,但通常是不明智的 编写依赖于差异的软件。首先, 将文档传递给任何常见的XML程序可能会改变它。 XML Infoset没有区分两种形式。 也好奇,为了什么目的这些信息对你有用..

编辑类似的应用程序应该保留用户首选的 格式,理想情况下,任何不会b / b 的应用程序都应该完全改变文档的结构。 /> - Richard

How do I detect empty tags if I have the DOM document? For example: <br /> and <br></br> I tried org.w3c.dom.Node.getFirstChild(), it returns null for both <br /> and <br></br> I also tried getNodeValue(), they both returns null also. I know <br /> and <br></br> are the same from the xml spec. Is there any way to tell the different syntax using DOM parser? Thanks, -John

解决方案

On 13 Apr 2005 18:23:59 -0700, "vega" <jo****@gmail> wrote:

How do I detect empty tags if I have the DOM document?For example: <br /> and <br></br>

You can''t and you don''t need to. In XML these are exactly equivalent(sic). www.w3/TR/2004/REC-xml-20...#sec-starttags "Empty-element tags MAY be used for any element which has no content, whether or not it is declared using the keyword EMPTY. For interoperability, the empty-element tag SHOULD be used, and SHOULD only be used, for elements which are declared EMPTY." There may be a useful difference you can find in the element''s definition from DTD or schema - i..e. EMPTY You can access this by either parsing it, or (more easily) by using a document parser that understands schema and offers a more direct link to the relevant one. This is the definition though, not the instance. It won''t tell you if the empty-element form of the tag in your document was used because it''s an EMPTY element, or just a non-empty element that happens to have no content in this instance. In general though, the way the document was serialised is not visible to an XML application and even more importantly there is NO reason why it needs to be. You just never need it. If you do think you need it, then the chances are that you''re in a non-XML context, such as XHTML or RSS. Although these are ostensibly XML protocols, they exist in an environment that''s still rooted in the HTML past. There may be valid reasons for still caring about things that a purely XML context wouldn''t need to.

<br/> and <br></br> are same according to XML spec.. I do not think any compliant XML parser would treat these two ways differently. So I think the XML parser cannot report this difference.. Just also curious, for what purpose this information is useful to you.. Regards, Mukul "vega" <jo****@gmail> wrote in message news:<11********************@z14g2000cwz.googlegro ups>...

How do I detect empty tags if I have the DOM document? For example: <br /> and <br></br> I tried org.w3c.dom.Node.getFirstChild(), it returns null for both <br /> and <br></br> I also tried getNodeValue(), they both returns null also. I know <br /> and <br></br> are the same from the xml spec. Is there any way to tell the different syntax using DOM parser? Thanks, -John

In article <b1*************************@posting.google> , Mukul Gandhi <mu**********@yahoo> wrote:

<br/> and <br></br> are same according to XML spec.. I do not thinkany compliant XML parser would treat these two ways differently. So Ithink the XML parser cannot report this difference.. An XML parser can report what it likes, but it would usually be unwise to write software that depended on the difference. For one thing, passing the document through any common XML program might well change it. The XML Infoset does not distinguish between the two forms. Just also curious, for what purpose this information is useful toyou..

Editor-like applications should preserve the user''s preferred formatting, and ideally so should any application that doesn''t completely alter the structure of the document. -- Richard

更多推荐

如何检测空标签?

本文发布于:2023-11-06 03:30:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!