如何在 SQL Server 中创建计数标记数的函数 [英] How to create function for count number of tags in SQL Server

查看:21
本文介绍了如何在 SQL Server 中创建计数标记数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server 2014中,我需要一个函数可以统计tags的数量,如果不等于tags open和closetags的数量,tag如果tag低,就添加相应的包.

对于这个例子或网站页面的源代码:

<ul><li>约翰</li><li>sara</li><li>马克</li><li>简<li>

计数(<) = 计数(>)
计数 () = 计数 ()

if count(<) >) --> 在标签元素前添加<
如果 count() > count() 然后在正确的位置添加 或删除.

解决方案

事实上,你用 xml 标记你的问题(与你不久放置的其他问题相同)清楚地表明,你对 XML...

有很深的误解

XML 不是 HTML!!!

许多人认为,它们是相关的,几乎相同,但是 - 尽管事实上,两者都在 <> 括号中使用标记 - 它们不是......

我们可能会讨论 XTHML,但是您的示例(此处和您的其他问题中)不是 xml-safe... XHTMLHTMLXML 的混合体.每个元素都必须正确关闭,不允许
,只有
,没有像

    这样的未闭合标签code> 在您的示例中... XML 对字符转义、命名空间和嵌套层次结构绝对严格.

    SQL Server 为处理有效的 XML 提供了很大帮助,但这对您无济于事.你必须在字符串基础上分析这个.但是 SQL Server 在字符串操作方面相当差,而且 - 当然!- 不是分析设计糟糕的网页的正确工具.

    In SQL Server 2014, I need a function that can count the number of tags, and if not equal the number of tags open and close tags, tag if the tag is low, add the appropriate package.

    For this example or source code of page of website:

    <div>
      <ul>
         <li>John</li>
         <li>sara</li>
         <li>mack</li>
         <li>jane<li>
    </div>
    

    count (<) = count (>)
    count (<tag>) = count (</tag>)

    if count(<) < count(>) --> add < before element of tag
    if count(<tag>) > count(</tag>) then add </tag> in correct position or delete.

    解决方案

    The fact, that you tag your question with xml (and the same with your other question you placed shortly) shows clearly, that you have a deep misconception of XML...

    XML is not HTML!!!

    Many people think, that they are related, almost the same, but - despite the fact, that both use markups in <> brackets - they aren't...

    We might discuss about XTHML, but your examples (here and in your other question) are not xml-safe... XHTML is an hybrid of HTML and XML. Every element must be closed correctly, no <br> is allows, only <br/>, no unclosed tags like <ul> in your example... XML is absolutely strict with character escaping, namespaces and nesting hierachies.

    SQL Server offers great help to deal with valid XML, but this cannot help you out. You have to analyse this on string base. But SQL Server is rather poor with string operations and is - for sure! - not the right tool to analyse poorly designed web pages.

    这篇关于如何在 SQL Server 中创建计数标记数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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