SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict amitjoshi's Avatar
    Join Date
    Jul 2005
    Location
    Oklahoma, USA
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question XML error: Invalid character

    I used this code to parse my XML file returned by a remote page saved at data.xml
    PHP Code:
     <?php
    $file 
    "data.xml";
    $depth = array();

    function 
    startElement($parser$name$attrs
    {
        global 
    $depth;
        for (
    $i 0$i $depth[$parser]; $i++) {
            echo 
    "  ";
        }
        echo 
    "$name\n";
        
    $depth[$parser]++;
    }

    function 
    endElement($parser$name
    {
        global 
    $depth;
        
    $depth[$parser]--;
    }

    $xml_parser xml_parser_create();
    xml_set_element_handler($xml_parser"startElement""endElement");
    if (!(
    $fp fopen($file"r"))) {
        die(
    "could not open XML input");
    }

    while (
    $data fread($fp4096)) {
        if (!
    xml_parse($xml_parser$datafeof($fp))) {
            die(
    sprintf("XML error: %s at line %d",
                        
    xml_error_string(xml_get_error_code($xml_parser)),
                        
    xml_get_current_line_number($xml_parser)));
        }
    }
    xml_parser_free($xml_parser);
    ?>
    But I get this error: XML error occurred at :Invalid character at line 78 what error is this and how can I solve this?

    Amit

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You'll need to view the XML that PHP generates and look for the error in there.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends on what's in the file. It's probably due to an invalid/unescaped character. Try wrapping any free text in <![CDATA[ Blah Blah Blah Blah ]]>

    Have a look at this:

    http://www.w3schools.com/xml/xml_cdata.asp


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •