Jump to content

Working with Dom-HTML?


Nolongerused3921

Recommended Posts

Currently I'm trying to figure out how to take a small bit of html, say

<input name="tesT" value="YAY" />

or

<input name="tesT" value="YAY">

or

<textarea name="moo">blah</textarea>

 

Edit, say, the value (Or innerHTML), an attribute or two, add an attribute, take one out, etc... Then export it back the same way it came in, but with the modifications. But I'm having two problems that are annoying me to no end.

 

1) I don't usually work with DOM, so I'm not quite sure how to edit attributes and the like. The HTML aspect isn't well documented, so any help here would be nice.

2) I'm getting extremely annoyed by the fact saveHTML() AND saveXML() both add all the extra stuff that I don't want. What's worse, it looks like even by importing the HTML with loadHtml, it adds the body tags which I don't need or want. How do I get around this? I want JUST the element(s) that go in, to come out.

 

	$domdoc = new DOMDocument();
	$domdoc->validateOnParse = false;
	$domdoc->loadHtml($element);
	$textarea = $domdoc->getElementsByTagName("textarea");
	$xml = simplexml_import_dom($domdoc);
	PrintNeatArrays($xml);

 

This is pretty much all I have right now.

Any help would be appreciated, thanks.

Link to comment
Share on other sites

Since your questions are really broad and general, its hard to answer them. I mean, what exactly do you want? It doesn't sound like you are having a specific problem, but rather just don't really understand how to use XML with PHP very well. Teaching you how to use PHP and XML is beyond the scope of one thread, especially seeing as this thread is in the 'help' section, and not the 'tutorials' section.

 

Maybe this can help you out: http://www.google.com/search?hl=en&safe=off&q=php+and+xml&btnG=Search

Link to comment
Share on other sites

  • 2 months later...

haku: I think his problem is specific. The one that don't understand is you.

I'm also getting annoyed by the mode that DOM Functions in PHP validate content.

 

Example:

 

I want to parse a website, and I know that a <p> tag with the "id" attribute set to "caption" holds user input.

But the user input can be ANYTHING, including those '<' and '>' characters (no htmlentities(), of course).

 

So, if I get the HTML:

 

<html>
<head>
</head>
<body>
<p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</p>
</body>
</html>

 

I can use the C14N() method to get raw data from a node, but the problem it's when i use loadHTML() method.

That method adds some extra information, and parses the tag <1337>, to something like:

 

<html>
<head>
</head>
<body>
<p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</1337></1337></p>
</body>
</html>

 

It adds the closing tags. Yes, correct form would be to change <1337> to </1337>, but user doesn't know this.

And the web-site doesn't use htmlentities(), (yes, tags are not displayed in screen, you can only see them in source code).

So, how can I get the REAL raw data?

I mean

<p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</p>

Instead of

<p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</1337></1337></p>

 

Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.