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 1039527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:06:39+00:00 2026-05-16T15:06:39+00:00

I’m relatively new to parsing XML files and am attempting to read a large

  • 0

I’m relatively new to parsing XML files and am attempting to read a large XML file with XMLReader.

<?xml version="1.0" encoding="UTF-8"?>
<ShowVehicleRemarketing environment="Production" lang="en-CA" release="8.1-Lite" xsi:schemaLocation="http://www.starstandards.org/STAR /STAR/Rev4.2.4/BODs/Standalone/ShowVehicleRemarketing.xsd">
  <ApplicationArea>
    <Sender>
      <Component>Component</Component>
      <Task>Task</Task>
      <ReferenceId>w5/cron</ReferenceId>
      <CreatorNameCode>CreatorNameCode</CreatorNameCode>
      <SenderNameCode>SenderNameCode</SenderNameCode>
      <SenderURI>http://www.example.com</SenderURI>
      <Language>en-CA</Language>
      <ServiceId>ServiceId</ServiceId>
    </Sender>
    <CreationDateTime>CreationDateTime</CreationDateTime>
    <Destination>
      <DestinationNameCode>example</DestinationNameCode>
    </Destination>
  </ApplicationArea>
...

I am recieving the following error

ErrorException [ Warning ]: XMLReader::read() [xmlreader.read]: compress.zlib://D:/WebDev/example/local/public/../upload/example.xml.gz:2: namespace error : Namespace prefix xsi for schemaLocation on ShowVehicleRemarketing is not defined

I’ve searched around and can’t find much useful information on using XMLReader to read XML files with namespaces — How would I go about defining a namespace, if that is in fact what I need to do.. little help? links to pertinent resources?

  • 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-05-16T15:06:39+00:00Added an answer on May 16, 2026 at 3:06 pm

    There needs to be a definition of the xsi namespace. E.g.

    <ShowVehicleRemarketing
      environment="Production"
      lang="en-CA"
      release="8.1-Lite"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.starstandards.org/STAR/STAR/Rev4.2.4/BODs/Standalone/ShowVehicleRemarketing.xsd"
    >
    

    Update: You could write a user defined filter and then let the XMLReader use that filter, something like:

    stream_filter_register('darn', 'DarnFilter');
    $src = 'php://filter/read=darn/resource=compress.zlib://something.xml.gz';
    $reader->open($src);
    

    The contents read by the compress.zlib wrapper is then “routed” through the DarnFilter which has to find the (first) location where it can insert the xmlns:xsi declaration. But this is quite messy and will take some afford to do it right (e.g. theoretically bucket A could contain xs, bucket B i:schem and bucket C aLocation=")


    Update 2: here’s an ad-hoc example of a filter in php that inserts the xsi namespace declaration. Mostly untested (worked with the one test I ran 😉 ) and undocumented. Take it as a proof-of-concept not production-code.

    <?php
    stream_filter_register('darn', 'DarnFilter');
    $src = 'php://filter/read=darn/resource=compress.zlib://d:/test.xml.gz';
    
    $r = new XMLReader;
    $r->open($src);
    while($r->read()) {
      echo '.';
    }
    
    class DarnFilter extends php_user_filter {
      protected $buffer='';
      protected $status = PSFS_FEED_ME;
    
      public function filter($in, $out, &$consumed, $closing)
      {
        while ( $bucket = stream_bucket_make_writeable($in) ) {
          $consumed += $bucket->datalen;
          if ( PSFS_PASS_ON == $this->status ) {
            // we're already done, just copy the content
            stream_bucket_append($out, $bucket);
          }
          else {
            $this->buffer .= $bucket->data;
            if ( $this->foo() ) {
              // first element found
              // send the current buffer          
              $bucket->data = $this->buffer;
              $bucket->datalen = strlen($bucket->data);
              stream_bucket_append($out, $bucket);
              $this->buffer = null;
              // no need for further processing
              $this->status = PSFS_PASS_ON;
            }
          }
        }
        return $this->status;
      }
    
      /* looks for the first (root) element in $this->buffer
      *  if it doesn't contain a xsi namespace decl inserts it
      */
      protected function foo() {
        $rc = false;
        if ( preg_match('!<([^?>\s]+)\s?([^>]*)>!', $this->buffer, $m, PREG_OFFSET_CAPTURE) ) {
          $rc = true;
          if ( false===strpos($m[2][0], 'xmlns:xsi') ) {
            echo ' inserting xsi decl ';
            $in = '<'.$m[1][0]
              . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
              . $m[2][0] . '>';    
            $this->buffer = substr($this->buffer, 0, $m[0][1])
              . $in
              . substr($this->buffer, $m[0][1] + strlen($m[0][0]));
          }
        }
        return $rc;
      }
    }
    

    Update 3: And here’s an ad-hoc solution written in C#

    XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
    // prime the XMLReader with the xsi namespace
    nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    
    using ( XmlReader reader = XmlTextReader.Create(
      new GZipStream(new FileStream(@"\test.xml.gz", FileMode.Open, FileAccess.Read), CompressionMode.Decompress),
      new XmlReaderSettings(),
      new XmlParserContext(null, nsmgr, null, XmlSpace.None)
    )) {
      while (reader.Read())
      {
        System.Console.Write('.');
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an XML file, the creators of it stuck in a bunch social
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.