Convert xml symbol notation

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

    #1

    Convert xml symbol notation

    Hi,

    I'm working on a script to download and parse a web page, and it
    includes xml symbol notation, such as ' for the ' character. Does
    anyone know of a pre-existing python script/lib to convert the xml
    notation back to the actual symbol it represents?

  • Gabriel Genellina

    #2
    Re: Convert xml symbol notation

    dumbkiwi wrote:
    I'm working on a script to download and parse a web page, and it
    includes xml symbol notation, such as ' for the ' character. Does
    anyone know of a pre-existing python script/lib to convert the xml
    notation back to the actual symbol it represents?
    Try the htmlentitydefs module.

    --
    Gabriel Genellina

    Comment

    • dumbkiwi

      #3
      Re: Convert xml symbol notation

      On Apr 7, 5:23 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
      dumbkiwi wrote:
      I'm working on a script to download and parse a web page, and it
      includes xml symbol notation, such as &#39; for the ' character. Does
      anyone know of a pre-existing python script/lib to convert the xml
      notation back to the actual symbol it represents?
      >
      Try the htmlentitydefs module.
      Is that a standard module? I can't see it anywhere - googled it.


      Comment

      • Gabriel Genellina

        #4
        Re: Convert xml symbol notation

        dumbkiwi wrote:
        On Apr 7, 5:23 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
        >>Try the htmlentitydefs module.
        >
        Is that a standard module? I can't see it anywhere - googled it.
        Sure! For quite a while, at least, since Python 1.5 (I can't go earlier
        in time...)

        Added Wed Sep 27 16:22:08 1995 UTC (11 years, 6 months ago) by guido

        --
        Gabriel Genellina


        Comment

        • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

          #5
          Re: Convert xml symbol notation

          >I'm working on a script to download and parse a web page, and it
          >includes xml symbol notation, such as &#39; for the ' character. Does
          >anyone know of a pre-existing python script/lib to convert the xml
          >notation back to the actual symbol it represents?
          >
          Try the htmlentitydefs module.
          That won't help: this is a character reference, not an entity reference.
          htmlentitydefs only contains the definitions of entities.

          Regards,
          Martin

          Comment

          • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

            #6
            Re: Convert xml symbol notation

            I'm working on a script to download and parse a web page, and it
            includes xml symbol notation, such as &#39; for the ' character. Does
            anyone know of a pre-existing python script/lib to convert the xml
            notation back to the actual symbol it represents?
            If you have this given in an XML file (rather than an HTML file which
            is not well-formed XML), you could use an XML parser for the entire
            file. This would automatically unescape character references. Likewise,
            you can parse it with HTMLParser, which will invoke the handle_charref
            method for these.

            If you just want to unescape references, you can use the code in



            HTH,
            Martin

            Comment

            • Gabriel Genellina

              #7
              Re: Convert xml symbol notation

              Martin v. Löwis wrote:
              I'm working on a script to download and parse a web page, and it
              includes xml symbol notation, such as &#39; for the ' character. Does
              Try the htmlentitydefs module.
              >
              That won't help: this is a character reference, not an entity reference.
              htmlentitydefs only contains the definitions of entities.
              Ouch! Sorry.

              --
              Gabriel Genellina

              Comment

              Working...