Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $doc = new DOMDocument('1.0', 'UTF-8');
- $xns = 'http://www.w3.org/2000/xmlns/';
- $mns = 'http://example.com/aBc/2/';
- $ons = 'http://example.com/test/2005/something';
- $ns = 'http://example.com/main/';
- $firstChild = $doc->createElement('firstChild');
- $firstChild->setAttributeNS($xns, 'xmlns:cns1', $mns);
- $firstChild->setAttributeNS($xns, 'xmlns:i', $ons);
- $elements = $doc->createElementNS($mns, 'cns1:elements');
- for($i = 0; $i < 3; $i++) {
- $e = $doc->createElementNS($mns, 'cns1:element');
- for($k = 0; $k < 2; $k++) {
- $r = rand(100, 999);
- $value = round(($r*rand(1,9))/rand(1,9), 2);
- $ce = $doc->createElementNS($mns, "cns1:elementValue$r", $value);
- $e->appendChild($ce);
- }
- $elements->appendChild($e);
- }
- $firstChild->appendChild($elements);
- $otherTag = $doc->createElementNS($mns, 'cns1:otherTag', 'some_value');
- $emptyTag = $doc->createElementNS($mns, 'cns1:emptyTag');
- $emptyTag->setAttributeNS($ons, 'i:nil', 'true');
- $firstChild->appendChild($otherTag);
- $firstChild->appendChild($emptyTag);
- $main = $doc->createElementNS($ns, 'main');
- $main->appendChild($firstChild);
- $doc->appendChild($main);
- header('Content-Type: text/xml');
- echo $doc->saveXML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement