I am modifying a form element. I have a function that is passed some HTML corresponding to the form (a div with form elements).
I modify the form as
function modify_form($paypal_button, $payment_params) {
    $d = new DOMDocument();
    $d->loadHTML($paypal_button);
    $xpath = new DOMXPath($d);
    $itemno =  $xpath->query('//form[@name="buynow"]/input[@name="item_number"]');
    $itemno->item(0)->setAttribute('value', 'SomeNewVal');
    $itemname =  $xpath->query('//form[@name="buynow"]/input[@name="item_name"]');
    $itemname->item(0)->setAttribute('value', 'SomeNewTitle');
    paypal_button = $d->saveHTML();
    return paypal_button;
}
What I am trying to return is simply a string, same format as what I was passed. That is, my modified version of $paypal_button.
With above, a bunch of HTML opening and closing tags are added - such as
?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
Whereas I need the format to be untouched.
By the way, are XPath and DOM functions overkill for this? I mean, $paypal_button is not a lot of text by any means... That is an aside.  At this point, just trying to figure out how to retrieve the modified markup after I do the two node modifications.
 
    