Re: How to prevent DomDocument from adding a !DOCTYPE.



Mathijs wrote:

I have some HTML content:
<div id="test1">
<div id="test2" class="testClass">
<span style="font-color: #900;" class="secondTestClass">
Testing<br>
</span>
ØøÅå_^{}\[~]|€ÆæßÉ@£$¥èéùìòÇ!"#¤%&'()*+,ÖÑܧ¿äöñüà-./:;<=>?¡Ä
</div>
</div>


Now i need to parse the HTML by getting all the class and id attributes and replace them with something else, and after that return the modified HTML.

If this were XHTML or you were working with complete HTML documents, then you would have a shot. Being HTML snippets, you are going to run into problems (different encodings, possibility of entities, etc..) - all of which need to be handled. You could probably hack the snippet a bit to "create" a full HTML document, but there's still no guarantee it will work correctly between different snippets.

On top of that, unlike working with XML, there is no way to output a subtree of HTML. You would need to use the XML serialization routines, which would most likely change the structure of your document (it would be XHTML compliant now).

Rob
.



Relevant Pages

  • Re: Margin and Floating Problem. Can someone explain me this behavior? Thank You.
    ... Shapper wrote: ... snippets of HTML and CSS. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: VB6 displays differently on different systems
    ... just a small collection of snippets for people who are new ... to HTML and webpage scripting. ... Okay, but you could make it better, you have the source code... ...
    (microsoft.public.vb.general.discussion)
  • Re: Replace everything between two strings?
    ... Uzytkownik "DesignGuy" napisal w wiadomosci ... > I need to replace everything between and including two snippets of HTML ...
    (comp.lang.php)
  • Re: How to prevent DomDocument from adding a !DOCTYPE.
    ... Now i need to parse the HTML by getting all the class and id attributes and replace them with something else, and after that return the modified HTML. ... If this were XHTML or you were working with complete HTML documents, then you would have a shot. ... You could probably hack the snippet a bit to "create" a full HTML document, but there's still no guarantee it will work correctly between different snippets. ... You need to have a tag with the right content-type in the parsed HTML. ...
    (php.general)
  • Re: Display multiple lines
    ... the display is still on a single line. ... have included some snippets of the code: ... Joe ... > Here is a sample of html output. ...
    (microsoft.public.inetserver.asp.general)