Parsing (IE) conditional comments

47 views
Skip to first unread message

David Lents

unread,
Aug 23, 2013, 6:24:46 PM8/23/13
to support-...@googlegroups.com
Hello,

I'm trying to parse an html document to extract the items inside the <head> section so that I can reconstitute them in a new document, but I haven't been able to figure out how to parse the conditional IE tags. Is there a recommended way to do that? Here's an excerpt of the html:

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>A Title</title>
    ...
    <!--[if lt IE 9]>
    <![endif]-->
    ...
</head>

I need to reproduce the conditional IE comments. I tried using QPXML's comment() method, but it doesn't seem to work. I've searched and wasn't able to find much info on parsing comments, and none specific to conditional comments like above. Any help would be appreciated.

TechnoSophos

unread,
Aug 28, 2013, 6:10:51 PM8/28/13
to support-...@googlegroups.com
I tried responding to this message earlier this week... did my response make it through?


--
You received this message because you are subscribed to the Google Groups "support-querypath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to support-queryp...@googlegroups.com.
To post to this group, send email to support-...@googlegroups.com.
Visit this group at http://groups.google.com/group/support-querypath.
For more options, visit https://groups.google.com/groups/opt_out.



--
http://technosophos.com
http://querypath.org

David Lents

unread,
Aug 28, 2013, 10:34:40 PM8/28/13
to support-...@googlegroups.com

No, I have not seen a response.

TechnoSophos

unread,
Aug 29, 2013, 12:18:32 PM8/29/13
to support-...@googlegroups.com
Ah, okay. My fault.

So... the short answer is that QueryPath doesn't do anything to parse IE comments. It ignores them like Chrome, Safari, and Firefox.

Unfortunately, the current "best way" is a little tedious:

$kids = qp($html, 'head')->children()->get();
$comments = array();
foreach ($kids as $someNode) {
   if ($someNode->nodeType == XML_COMMENT_NODE) {
     $comments[] = $someNode;
  }
}

That gives you an array of these guys: http://www.php.net/manual/en/class.domcomment.php

Based on what you're asking for, I'm wondering how much sense it makes to add this (as a better comment() function) to QueryPath's core. Your use case makes perfect sense to me.

Matt

David Lents

unread,
Sep 1, 2013, 6:45:26 PM9/1/13
to support-...@googlegroups.com
Matt,

Thanks for the tip, I'll give that a try!
Reply all
Reply to author
Forward
0 new messages