How to create function for count number of tags in SQL Server

不打扰是莪最后的温柔 提交于 2019-12-04 06:02:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/39434747/how-to-create-function-for-count-number-of-tags-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!