Regular Expressions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wolfson

    Regular Expressions

    Given an xml string s that looks like:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE foo PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN
    http://www.goo.com/xml_dtds/zoo.dtd">
    <xxx version="1.01">
    <zzz>ggg</zzz>
    </xxx>

    How do you remove the stuff within a <!DOCTYPE ... > tag such that the
    result
    is:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <xxx version="1.01">
    <zzz>ggg</zzz>
    </xxx>

    s = System.Text.Reg ularExpressions SystemRegex.Rep lace(s, PATTERN, "")?

    In other words, what should I put in for PATTERN?

    I tried "<!DOCTYPE* >" but that did not work.

    Thanks,
    Jon
  • Sreejumon[MVP]

    #2
    Regular Expressions

    hi Jon,

    I am not sure abt the regular expression. But You can
    acheive the same result using teh XmlDocument. First load
    the cml to XmlDocument and then remove your second node.

    regards
    Sreejumon[MVP]
    DOTNET makes IT happen[color=blue]
    >-----Original Message-----
    >Given an xml string s that looks like:
    >
    ><?xml version="1.0" encoding="iso-8859-1"?>
    ><!DOCTYPE foo PUBLIC "-//Netscape Communications//DTD RSS[/color]
    0.91//EN[color=blue]
    >http://www.goo.com/xml_dtds/zoo.dtd">
    ><xxx version="1.01">
    > <zzz>ggg</zzz>
    ></xxx>
    >
    >How do you remove the stuff within a <!DOCTYPE ... > tag[/color]
    such that the[color=blue]
    >result
    >is:
    >
    ><?xml version="1.0" encoding="iso-8859-1"?>
    ><xxx version="1.01">
    > <zzz>ggg</zzz>
    ></xxx>
    >
    >s = System.Text.Reg ularExpressions SystemRegex.Rep lace(s,[/color]
    PATTERN, "")?[color=blue]
    >
    >In other words, what should I put in for PATTERN?
    >
    >I tried "<!DOCTYPE* >" but that did not work.
    >
    >Thanks,
    >Jon
    >.
    >[/color]

    Comment

    • Peter McMahon [MVP]

      #3
      Re: Regular Expressions

      Hi Jonathan

      A regex pattern that works (i.e. matches) is "<!DOCTYPE[^>]*>". i.e.

      s = System.Text.Reg ularExpressions .Regex.Replace( s, "<!DOCTYPE[^>]*>", "")

      If you want to find out more about Regular Expressions, check under
      VS.NET->.NET Framework->Reference->Regular Expression Language Elements in
      the VS.NET Help.

      Peter

      "Jonathan Wolfson" <jon3825@hotmai l.com> wrote in message
      news:a6c92108.0 307010900.7e5d9 d70@posting.goo gle.com...[color=blue]
      > Given an xml string s that looks like:
      >
      > <?xml version="1.0" encoding="iso-8859-1"?>
      > <!DOCTYPE foo PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN
      > http://www.goo.com/xml_dtds/zoo.dtd">
      > <xxx version="1.01">
      > <zzz>ggg</zzz>
      > </xxx>
      >
      > How do you remove the stuff within a <!DOCTYPE ... > tag such that the
      > result
      > is:
      >
      > <?xml version="1.0" encoding="iso-8859-1"?>
      > <xxx version="1.01">
      > <zzz>ggg</zzz>
      > </xxx>
      >
      > s = System.Text.Reg ularExpressions SystemRegex.Rep lace(s, PATTERN, "")?
      >
      > In other words, what should I put in for PATTERN?
      >
      > I tried "<!DOCTYPE* >" but that did not work.
      >
      > Thanks,
      > Jon[/color]


      Comment

      Working...