|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55127 SimpleXML and HTML5 microformat
Submitted: 2011-07-04 07:03 UTC Modified: 2011-07-04 08:09 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: frederic dot auguste at gmail dot com Assigned:
Status: Wont fix Package: SimpleXML related
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: frederic dot auguste at gmail dot com
New email:
PHP Version: OS:


 [2011-07-04 07:03 UTC] frederic dot auguste at gmail dot com
We would like to manipulate and genere HTML5 microformat.

Parsing a HTML5 microformat with simpleXML is not possible : Some warning are 
generated and simplexml_load_string function return false.

The problem is with the itemscope attribute : It has no value.

Our XML is available on this web site :

Can you add these manipulations in simpleXML API ?
 * add attribut without value
 * parsing XML with attribute without value.


Test script:
$xml = <<<XML
<div itemscope itemtype="">
  <span itemprop="name">Jane Doe</span>
  <img src="janedoe.jpg" itemprop="image" />

  <span itemprop="jobTitle">Professor</span>
  <div itemprop="address" itemscope itemtype="">
    <span itemprop="streetAddress">
      20341 Whitworth Institute
      405 N. Whitworth
    <span itemprop="addressLocality">Seattle</span>,
    <span itemprop="addressRegion">WA</span>
    <span itemprop="postalCode">98052</span>
  <span itemprop="telephone">(425) 123-4567</span>
  <a href="" itemprop="email"></a>

  Jane's home page:
  <a href="" itemprop="url"></a>

  Graduate students:
  <a href="" itemprop="colleagues">
    Alice Jones</a>
  <a href="" itemprop="colleagues">
    Bob Smith</a>

$a = simplexml_load_string($xml);

if($a == false) {
	echo "XML not valid"; 
else {
	echo $a->asXML();


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-04 08:04 UTC]
-Status: Open +Status: Wont fix
 [2011-07-04 08:04 UTC]
By definition, it's not valid XML. It's already possible to use SimpleXML to 
manipulate this markup by using DOMDocument::loadHTML() first; eg:

$doc = new DOMDocument;
$a = simplexml_import_dom($doc->documentElement);

I don't really see any point complicating the SimpleXML API to support this, 
given the workaround is that easy.
 [2011-07-04 08:09 UTC]
Additionally you can use tidy to create somehow valid xhtml out of a broken html 
 [2012-09-14 18:27 UTC] blasterdrp at gmail dot com
"I don't really see any point complicating the SimpleXML API to support this, 
given the workaround is that easy."

The DOMDocument class is disrespectful toward input HTML and makes a lot of assumptions that you can't persuade it from making. It self-terminates tags you may not want to self-terminate, such as <script/>, or leaves open tags you may want to close, such as <li>, depending on whether or not you put it in quirks mode or strict mode. Furthermore it also arbitrarily adds DTDs if it doesn't like the one you already have (<!DOCTYPE html> is acceptable for HTML 5), and the same with meta tags, and so forth.

The DOMDocument should only change what you tell it to change, but instead it changes everything, and there's no way to tell it not to.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 13:01:29 2024 UTC