Open k7n4n5t3w4rt opened 12 years ago
Yeah it needs valid XML. There is a lib for parsing HTML5 in php though.
This whole HTML5 is not XHTML thing strikes me as an odd step backwards ... On 2012-06-30 9:16 PM, "Kynan Stewart Hughes" < reply@reply.github.com> wrote:
I'm trying to use the HTML Boilerplate (http://html5boilerplate.com/) as my base template. Fragmentify is having kittens:
$ php index.php PHP Warning: DOMDocument::loadXML(): StartTag: invalid element name in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Catchable fatal error: Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given, called in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 42 and defined in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 185
Is the problem HTML5 Boilerplate or does Fragmentify have a problem with HTML5 not looking like valid XML?
Reply to this email directly or view it on GitHub: https://github.com/iaindooley/Fragmentify/issues/1
It occurs to me that if you want to start using H5BP with fragmentify it would be sensible to fork it on github and create a second repo that is valid XML.
I don't mean valid XML in terms of all the XML bullshit that doesn't matter (doctypes, namespaces and all that garbage that only like 3 people in the world really understand) but valid XML in terms of the nodes being well formed so that you can use PHPs standard DOM parsing tools.
You can also modify Fragmentify to use loadHTML instead of loadXML but we've found that it's quite error prone because it "fails silently" if your document isn't well formed (like if you miss a closing p tag or something) which can lead to wild and crazy results - much easier to have things fail predictably.
Since
is just as valid in an HTML5 document as
it seems
idiotic to switch back to pre-XHTML shitness just because "we can" - like
as if everyone who writes markup is heaving a great sigh of relief that
they no longer need to delimit their attributes with double quotes and
self-close br tags.
In actual fact we could learn a lot from the work that Kroc Camen did on his DOMTemplate library which has a lot of stuff for correct entities and stuff that we haven't really addressed with Fragmentify yet http://github.com/iaindooley/DOMTemplate/ or the original https://github.com/kroc/DOMTemplate
On Sat, 30 Jun 2012, Kynan Stewart Hughes wrote:
I'm trying to use the HTML Boilerplate (http://html5boilerplate.com/) as my base template. Fragmentify is having kittens:
$ php index.php PHP Warning: DOMDocument::loadXML(): StartTag: invalid element name in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Catchable fatal error: Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given, called in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 42 and defined in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 185
Is the problem HTML5 Boilerplate or does Fragmentify have a problem with HTML5 not looking like valid XML?
Reply to this email directly or view it on GitHub: https://github.com/iaindooley/Fragmentify/issues/1
ok. i hacked the HTML5Lib and this into class Fragmentify:
public function getDoc() {
if($this->doc == null) {
// http://code.google.com/p/html5lib/source/browse/php/README
require_once 'HTML5/Parser.php';
$data = file_get_contents($this->path);
$this->doc = HTML5_Parser::parse($data);
}
return $this->doc;
}
works fine in that it outputs HTML, but not the actual fragmentifying attributes. I'm trying with "replace".
$raw_markup = Fragmentify::render('packages/kynan/views/index.html');
Where base.html is the full HTML5Boilderplate and my index.html is referencing it:
The output is the HTML5Boilerplate, but without the replace. I've delved into fragmentary, but it makes my brain fragmentary and i can't work out how the hell it's working. I guess I might have to use the HTML5Lib parser in place of some other parsing currently done by DOMDocument methods (like fragments), but i don't really now where to start.
Am i generally on the right track do you think?
Okay so I think this is the very reason why it's a bad idea to use invalid HTML (ie. why we don't juse loadHTML instead of loadXML) - things get confused and although they're valid XML when parsed it's not what you intended.
So I think you'd be better off creating a version of the HTML5BP repo which confirms to XML like syntax, ie. enclose all attributes in " and make sure you're self closing tags etc.
What's happening is that the base document is being rendered and none of the replacements are working. Doesn't look like it would be particularly easy to fix, and the HTML5_Parser library is "pre-alpha".
Looks like bad voodoo to me, and the only reason it's not parsing as XML is because of the blind idealism of the HTML5BP authors (this is HTML! not XML! why self close!).
Self-closing tags and making the document well formed XML doesn't invalidate it as HTML5, so why wouldn't do that?
If I were you I'd just fork their project and go ahead and correct these XML shennanigans once and for all.
On Tue, 3 Jul 2012, Kynan Stewart Hughes wrote:
ok. i hacked the HTML5Lib and this into class Fragmentify:
public function getDoc() { if($this->doc == null) { // http://code.google.com/p/html5lib/source/browse/php/README require_once 'HTML5/Parser.php'; $data = file_get_contents($this->path); $this->doc = HTML5_Parser::parse($data); } return $this->doc; }
works fine in that it outputs HTML, but not the actual fragmentifying attributes. I'm trying with "replace".
$raw_markup = Fragmentify::render('packages/kynan/views/index.html');
Where base.html is the full HTML5Boilderplate and my index.html is referencing it:
This is it PLACEHOLDERThe output is the HTML5Boilerplate, but without the replace. I've delved into fragmentary, but it makes my brain fragmentary and i can't work out how the hell it's working. I guess I might have to use the HTML5Lib parser in place of some other parsing currently done by DOMDocument methods (like fragments), but i don't really now where to start.
Am i generally on the right track do you think?
Reply to this email directly or view it on GitHub: https://github.com/iaindooley/Fragmentify/issues/1#issuecomment-6731891
If I were you I'd just fork their project and go ahead and correct these XML shennanigans once and for all.
Yeah, I had a go. It's not that easy. There are quite a few things in HTML5bp that kill the loadXML. But I'll persevere.
You can use something like @$doc = DOMDocument::loadHTML($strHTML, LIBXML_NOWARNING | LIBXML_NOERROR)
to avoid warnings and get "any HTML" to DOM. It works better than tidy::html
... use DOMDocument::loadXML($doc->saveXML($doc->documentElement))
to strip DOCTYPE after convertion, will be a perfect XML.
I'm trying to use the HTML Boilerplate (http://html5boilerplate.com/) as my base template. Fragmentify is having kittens:
$ php index.php PHP Warning: DOMDocument::loadXML(): StartTag: invalid element name in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 193 PHP Catchable fatal error: Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given, called in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 42 and defined in /Library/WebServer/Documents/kynan.localhost/build/packages/fragmentify/fragmentify.class.php on line 185
Is the problem HTML5 Boilerplate or does Fragmentify have a problem with HTML5 not looking like valid XML?