Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. $doc = new DOMDocument('1.0', 'UTF-8');
  2. $xns = 'http://www.w3.org/2000/xmlns/';
  3. $mns = 'http://example.com/aBc/2/';
  4. $ons = 'http://example.com/test/2005/something';
  5. $ns =  'http://example.com/main/';
  6.  
  7. $firstChild = $doc->createElement('firstChild');
  8. $firstChild->setAttributeNS($xns, 'xmlns:cns1', $mns);
  9. $firstChild->setAttributeNS($xns, 'xmlns:i', $ons);
  10.  
  11. $elements = $doc->createElementNS($mns, 'cns1:elements');
  12.  
  13. for($i = 0; $i < 3; $i++) {
  14.     $e = $doc->createElementNS($mns, 'cns1:element');
  15.     for($k = 0; $k < 2; $k++) {
  16.         $r = rand(100, 999);
  17.         $value = round(($r*rand(1,9))/rand(1,9), 2);
  18.         $ce = $doc->createElementNS($mns, "cns1:elementValue$r", $value);
  19.         $e->appendChild($ce);
  20.     }
  21.     $elements->appendChild($e);
  22. }
  23. $firstChild->appendChild($elements);
  24.  
  25. $otherTag = $doc->createElementNS($mns, 'cns1:otherTag', 'some_value');
  26. $emptyTag = $doc->createElementNS($mns, 'cns1:emptyTag');
  27. $emptyTag->setAttributeNS($ons, 'i:nil', 'true');
  28.  
  29. $firstChild->appendChild($otherTag);
  30. $firstChild->appendChild($emptyTag);
  31.  
  32. $main = $doc->createElementNS($ns, 'main');
  33. $main->appendChild($firstChild);
  34.  
  35. $doc->appendChild($main);
  36.  
  37.  
  38. header('Content-Type: text/xml');
  39.  
  40. echo $doc->saveXML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement