Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:17:52+00:00 2026-06-01T21:17:52+00:00

We have a script that parses XML feeds from user generated sources which from

  • 0

We have a script that parses XML feeds from user generated sources which from time to time contain improperly formated entries with special characters.

While I would normally just run utf8_encode() on the line, I’m not certain how to do this as DOM is progressively reading the file and the error is thrown as the expand command takes place.

Since simple_xml chokes on the code, subsequent lines are also off.

Here’s the code.

$z = new XMLReader; 
$z->open($filename); $doc = new DOMDocument('1.0','UTF-8');         
while ($z->read() && $z->name !== 'product');   
while ($z->nodeType == XMLReader::ELEMENT AND $z->name === 'product'){
$producti = simplexml_import_dom($doc->importNode($z->expand(), true));
print_r($producti);
}

Errors:

Message: XMLReader::expand(): foo.xml:29081: parser error : Input is
not proper UTF-8, indicate encoding ! Bytes: 0x05 0x20 0x2D 0x35

Severity: Warning

Message: XMLReader::expand(): An Error
Occured while expanding

Filename: controllers/feeds.php

Line Number: 106

Message: Argument 1 passed to DOMDocument::importNode() must be an
instance of DOMNode, boolean given

Filename:
controllers/feeds.php

Line Number: 106

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:17:55+00:00Added an answer on June 1, 2026 at 9:17 pm

    Use HTML Tidy library first to clean your string.

    Also I’d better use DOMDocument instead of XMLReader.

    Something like that:

            $tidy = new Tidy;
    
            $config = array(
                    'drop-font-tags' => true,
                    'drop-proprietary-attributes' => true,
                    'hide-comments' => true,
                    'indent' => true,
                    'logical-emphasis' => true,
                    'numeric-entities' => true,
                    'output-xhtml' => true,
                    'wrap' => 0
            );
    
            $tidy->parseString($html, $config, 'utf8');
    
            $tidy->cleanRepair();
    
            $xml = $tidy->value; // Get clear string
    
            $dom = new DOMDocument;
    
            $dom->loadXML($xml);
    
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Requirements : I have a Python project which parses data feeds from multiple sources
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a script that is designed to parse XML postbacks from Ultracart, right
I have a php script that parses XML files and creates a large SQL
I have a python script that parses an XML file that contains part information
I have a PHP script that imports and parses XML files and saves the
I have written a Python script that takes a 1.5 G XML file, parses
I've got a speed question. I have a bash script which parses information from
I have a js script that reads and parses XML. It obtains the XML
I have a script that parses xml file to generate SQLite table automatically. And,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.