Skip to content

Peachpie.Library.XmlDom.XMLWriter: Error writing namespace attribute 'xmlns' #1142

Description

@wujwmail

Running error message:

        Unhandled exception. System.Xml.XmlException: The prefix '' cannot be redefined from '' to 'http://schemas.openxmlformats.org/package/2006/content-types' within the same start element tag.
           at System.Xml.XmlWellFormedWriter.PushNamespaceExplicit(String prefix, String ns)
           at System.Xml.XmlWellFormedWriter.WriteEndAttribute()
           at Peachpie.Library.XmlDom.XMLWriter.<>c__DisplayClass41_0.<writeAttribute>b__2()
           at Peachpie.Library.XmlDom.XMLWriter.CheckedCall(Action operation)
           at Peachpie.Library.XmlDom.XMLWriter.writeAttribute(String name, String content)
           ....

PHPExcel source code (PHPExcel-1.8.1): https://github.com/PHPOffice/PHPExcel

\PHPExcelPhpCsLib\PHPExcel\Writer\Excel2007\ContentTypes.php:line 61
This statement seems to be wrong:

     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');

demo download -> https://github.com/wujwmail/PHPExcel_test/tree/master


A php example for testing writeAttribute

<?php
 
  $xml = new XMLWriter();
  $xml->openMemory();

  $xml->startElement('element');
  /*
    An error occurs when using xmlns attribute names
  */
  $xml->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');

  /*
    It is normal to use attribute names other than xmlns attribute names.
  */
  $xml->writeAttribute('not_xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');

  $xml->endElement();

  echo $xml->flush();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions