0

Simply put I have HTML that looks like this:

<ul>
  <li>Unorderd Item 1</li>
  <li>Unordered Item 2</li>
  <li>Unordered Item 3
    <ol>
       <li>Ordered Item 1</li>
       <li>Ordered Item 2</li>
    </ol>
  </li>
  <li>Unordered Item 4</li>
</ul>

I'm looking for a regular expression or some logic of that nature that replaces the <li> tag with something depending on what its parent list element is.

I can use straight up RegEx or I can use (more than likely my route here) the .Net System.Text.RegularExpressions class so:

Regex.Replace

Regex.Matches

<-- I know I could/should be using a HTML parser but this is being used in conjunction with a XSLT config doc. So using a Regex seems to be the best way to go. -->

Desired Output:

<ul>
   <Unordered>Unordered Item 1</Unordered>
   <Unordered>....</Unordered>
     <ol>
        <Ordered>......</Ordered>
        <Ordered>......</Ordered>
     </ol>
   <Unordered>.....</Unordered>
 </ul>  
sacbeme
  • 35
  • 1
  • 8
  • you want to replace with what..can you provide some sample output..also what have tried! – Anirudha Jul 11 '13 at 17:58
  • What I want to replace with isn't that important, what it gets replaced with depends on which type of list is its parent (e.g. the
  • tag can be: or ).
  • – sacbeme Jul 11 '13 at 18:02
  • no one would be able to ans your question unless you provide us with some sample output for the above html..i have no idea about what you are asking.. – Anirudha Jul 11 '13 at 18:05
  • 1
    Do not use regex to parse HTML! It is **not** the best way to go! Use the DOM! –  Jul 11 '13 at 18:06
  • You definitely don't want to use regex for this. You need a HTML parser -- an XML parser might also work. – Mark Lakata Jul 11 '13 at 18:06
  • 3
    http://stackoverflow.com/a/1732454/47589 –  Jul 11 '13 at 18:07
  • Are you using xslt to transform this, or what is meant by "in conjuction with"? You could probably use some XQuery update. Just stay away from trying to regex this, as mentioned. – carlpett Jul 11 '13 at 18:15
  • possible duplicate of [RegEx match open tags except XHTML self-contained tags. You can't parse (X)HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Erik Philips Jul 11 '13 at 18:18