Reputation: 428
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.
Upvotes: 0
Views: 192
Reputation: 67311
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
...
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.
Upvotes: 2