Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two common ways to do this.</p> <p><strong><a href="http://php.net/manual/en/book.dom.php" rel="nofollow">DOMDocument</a></strong></p> <p>DOM XML was deprecated in favor of this. It follows the W3C specification so you have typical DOM methods such as <code>getElementsByTagName</code>, <code>getElementById</code>, <code>appendChild</code>, <code>removeChild</code>, etc. It also uses appropriate classes such as <code>DOMElement</code>, <code>DOMNode</code> and <code>DOMNodeList</code>.</p> <pre><code>$doc = new DOMDocument('1.0','utf-8'); $root = $doc-&gt;appendChild($doc-&gt;createElement('markers')); // output echo $doc-&gt;saveXML(); </code></pre> <p>If you know already how to traverse the DOM in Javascript you pretty much already know how to do it in PHP using DOMDocument and other related classes.</p> <p>I don't know why Shankar's answer was downvoted unless there are people who favor the next method.</p> <p><strong><a href="http://php.net/manual/en/book.simplexml.php" rel="nofollow">SimpleXML</a></strong></p> <p>SimpleXML attempts to live up to its name by using only two classes and using a parent-child structure to traverse the document.</p> <pre><code>$doc = new SimpleXMLElement('&lt;markers/&gt;'); // output echo $doc-&gt;asXML(); </code></pre> <p>An element in itself evaluates to its contents if it's treated as a string, and attributes can be accessed as you would access elements of an associative array.</p> <pre><code>$marker = $doc-&gt;addChild('marker'); $marker-&gt;addAttribute('color','red'); </code></pre> <p>You can also do this if you don't really need to hang onto the reference to the element. You can't add multiple attributes using this method, however, so you'd still need the previous to add new attributes without traversing the whole document.</p> <pre><code>$doc-&gt;addChild('marker')-&gt;addAttribute('color','red'); </code></pre> <p>Access your elements and attributes like so:</p> <pre><code>// red echo $doc-&gt;marker[0]['color']; </code></pre> <p>To set the element value just set it.</p> <pre><code>$doc-&gt;marker[0] = 'Text Value'; // Text Value echo $doc-&gt;marker[0]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload