Parse embedded html tags within XML file?

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

    #1

    Parse embedded html tags within XML file?

    I am trying to write a general function XML file parser, but it keeps
    choking when it finds embedded HTML within the text, for example:

    <item>
    <title>New PHP eBooks in PDF</title>
    <description>
    <p style="color: red">This entry was brought to you by <a
    href="http://tutorials.locke rgnome.com/">Lockergno me's
    Tutorials</a></p><strong>New PDFs are Available!</strong>...
    </description>

    When I try to read this all I get is "p style=" (no quotes). Is there a
    function or routine I can use to read this as text so that it can be
    printed out in HTML?

    Thanks,

    Miki
  • Barbara \bev\ T.

    #2
    Re: Parse embedded html tags within XML file?

    Hi
    [color=blue]
    > I am trying to write a general function XML file parser, but it keeps
    > choking when it finds embedded HTML within the text, for example:
    >
    > <item>
    > <title>New PHP eBooks in PDF</title>
    > <description>
    > <p style="color: red">This entry was brought to you by <a
    > href="http://tutorials.locke rgnome.com/">Lockergno me's
    > Tutorials</a></p><strong>New PDFs are Available!</strong>...
    > </description>
    >
    > When I try to read this all I get is "p style=" (no quotes). Is there a
    > function or routine I can use to read this as text so that it can be
    > printed out in HTML?[/color]

    you may try to treat anything beetween description tags with htmlentities()
    a then revert it with html_entity_dec ode().

    --
    hope it helps
    Barbara

    Comment

    • Michelle

      #3
      Re: Parse embedded html tags within XML file?

      Barbara "bev" T. wrote:[color=blue]
      > Hi
      >[color=green]
      >> I am trying to write a general function XML file parser, but it keeps
      >> choking when it finds embedded HTML within the text, for example:
      >>
      >> <item>
      >> <title>New PHP eBooks in PDF</title>
      >> <description>
      >> <p style="color: red">This entry was brought to you by
      >> <a href="http://tutorials.locke rgnome.com/">Lockergno me's
      >> Tutorials</a></p><strong>New PDFs are Available!</strong>...
      >> </description>
      >>
      >> When I try to read this all I get is "p style=" (no quotes). Is there
      >> a function or routine I can use to read this as text so that it can
      >> be printed out in HTML?[/color]
      >
      >
      > you may try to treat anything beetween description tags with htmlentities()
      > a then revert it with html_entity_dec ode().
      >[/color]
      I tried that but I can't seem to insert the conversion function into the
      the xml parser read at the proper time. For example this code:

      if (!xml_parse($xm l_parser, htmlentities($d ata), feof($source)))
      {
      die(sprintf("XM L error: %s at line %d",
      xml_error_strin g(xml_get_error _code($xml_pars er)),
      xml_get_current _line_number($x ml_parser)));
      }

      produces the following error:
      "XML error: not well-formed (invalid token) at line"

      inserting the function later does nothing??

      miki

      Comment

      • Barbara \bev\ T.

        #4
        Re: Parse embedded html tags within XML file?

        > I tried that but I can't seem to insert the conversion function into the[color=blue]
        > the xml parser read at the proper time. For example this code:
        >
        > if (!xml_parse($xm l_parser, htmlentities($d ata), feof($source)))
        > {
        > die(sprintf("XM L error: %s at line %d",
        > xml_error_strin g(xml_get_error _code($xml_pars er)),
        > xml_get_current _line_number($x ml_parser)));
        > }[/color]

        well that's not good.
        assuming you don't know the tags that may occur in description part, you
        should be able to determine the xml tags that'll be there, so
        here's what I did (worked for me):

        function startElement($p arser, $name, $attrs) {
        if (in_array($tag_ name,$tags_arra y)){
        //do something
        } else return false;
        }

        where tags_array could be: array('ITEMS',' ITEM','TITLE',' DESCRIPTION')

        if you don't know the xml tags... we'll have a problem unless someone else
        helps you :)

        --
        Regards
        Barbara

        Comment

        Working...