Note that there are some explanatory texts on larger screens.

plurals
  1. POGetElementsByTagName alternative to DOMDocument
    primarykey
    data
    text
    <p>I am creating an HTML file with DOMDocument, but I have a problem at the time of the search by the getElementsByTagName method. What I found is that as I'm generating the hot, does not recognize the labels that I inserted.</p> <p>I tried with DOMXPath, but to no avail :S</p> <p>For now, I've got to do is go through all the children of a node and store in an array, but I need to convert that score DOMNodeList, and in doing</p> <pre><code>return (DOMNodeList) $ my_array; </code></pre> <p>generates a syntax error.</p> <p>My specific question is, how I can do to make a search for tags with the getElementsByTagName method or other alternative I can offer to achieve the task?</p> <p>Recalling that the DOMDocument I'm generating at the time.</p> <p>If you need more information, I'll gladly place it in the question.</p> <p>Sure Jonathan Sampson.</p> <p>I apologize for the editing of the question the way. I did not quite understand this forum format.</p> <p>For a better understanding of what I do, I put the inheritance chain.</p> <p>I have this base class</p> <pre><code>abstract class ElementoBase { ... } </code></pre> <p>And I have this class that inherits from the previous one, with an abstract function insert (insert)</p> <pre><code>abstract class Elemento extends ElementoBase { ... public abstract function insertar ( $elemento ); } </code></pre> <p>Then I have a whole series of classes that represent the HTML tags that inherit from above, ie.</p> <pre><code>class A extends Elemento { } ... </code></pre> <p>Now the code I use to insert the labels in the paper is as follows:</p> <pre><code>public function insertar ( $elemento ) { $this-&gt;getElemento ()-&gt;appendChild ( $elemento-&gt;getElemento () ); } </code></pre> <p>where the function getElemento (), return a DOMElement</p> <p>Moreover, before inserting the element do some validations that depend on the HTML tag that is to be inserted, because they all have very specific specifications.</p> <p>Since I'm generating HTML code at the same time, it is obvious that there is no HTML file.</p> <p>To your question, the theory tells me to do this:</p> <pre><code>$myListTags = $this-&gt;getElemento ()-&gt;getElementsByTagName ( $tag ); </code></pre> <p>but I always returns null, this so I researched it because I'm not loading the HTML file, because if I</p> <pre><code>$myHtmlFile = $this-&gt;getDocumento ()-&gt;loadHTMLFile ( $filename ); $myListTags = $myHtmlFile-&gt;getElementsByTagName ( $etiqueta ); </code></pre> <p>I do return the list of HTML tags</p> <p>If you need more information, I'll gladly place it in the question.</p>
    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.
 

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