Php dom get child node by tag name
Show
I made 3 changes to your code, 2 relevant to this issue and one to just update the syntax. The important 2 changes are:
And the one less relevant change was:
Note:
You also mentioned that you get a blank page once you added the PHP DOM: How to get child elements by tag name in an elegant mannerQuestions : PHP DOM: How to get child elements by tag name in an elegant manner2022-09-27T07:17:21+00:00 2022-09-27T07:17:21+00:00 802 I'm parsing some XML with PHP DOM extension anycodings_xml in order to store the data in some other anycodings_xml form. Quite unsurprisingly, when I parse an anycodings_xml element I pretty often need to obtain all anycodings_xml children elements of some name. There is the anycodings_xml method anycodings_xml DOMElement::getElementsByTagName($name), but anycodings_xml it returns all descendants with that name, anycodings_xml not just immediate children. There is also anycodings_xml the property DOMNode::$childNodes but (1) it anycodings_xml contains node list, not element list, and anycodings_xml even if I managed to turn the list items anycodings_xml into elements (2) I'd still need to check anycodings_xml all of them for the name. Is there really no anycodings_xml elegant solution to get only the children of anycodings_xml some specific name or am I missing something anycodings_xml in the documentation? Some illustration:
Total Answers 3 31 Answers 1 : of PHP DOM: How to get child elements by tag name in an elegant manner
simple iteration process
0 2022-09-27T07:17:21+00:00 2022-09-27T07:17:21+00:00Answer Link mRahman 5 Answers 2 : of PHP DOM: How to get child elements by tag name in an elegant mannerAn elegant manner I can imagine would be anycodings_xml using a FilterIterator that is suitable anycodings_xml for the job. Exemplary one that is able anycodings_xml to work on such a said DOMNodeList and anycodings_xml (optionally) accepting a tagname to anycodings_xml filter for as an exemplary anycodings_xml DOMElementFilter from the Iterator anycodings_xml Garden does:
This will give the results you're anycodings_xml looking for:
You can find DOMElementFilter in the anycodings_xml Development branch now. It's perhaps anycodings_xml worth to allow * for any tagname as it's anycodings_xml possible with getElementsByTagName("*") anycodings_xml as well. But that's just some anycodings_xml commentary. Hier is a working usage example online: anycodings_xml https://eval.in/57170 0 2022-09-27T07:17:21+00:00 2022-09-27T07:17:21+00:00Answer Link raja 3 Answers 3 : of PHP DOM: How to get child elements by tag name in an elegant mannerMy solution used in a production: Finds a needle (node) in a haystack anycodings_xml (DOM)
Usage:
Returns DOM element from parent anycodings_xml countries node by specified attribute anycodings_xml iso using country ISO code 'NL', anycodings_xml basically like a real search would do. anycodings_xml Find a certain country by it's name in anycodings_xml an array / object. Another usage example:
Returns DOM node element containing only anycodings_xml single (root) node, without searching by anycodings_xml any attribute. Note: for this you must anycodings_xml make sure that root nodes are unique by anycodings_xml elements' tag name, e.g. anycodings_xml countries->country[ISO] - countries anycodings_xml node here is unique and parent to all anycodings_xml child nodes. 0 2022-09-27T07:17:21+00:00 2022-09-27T07:17:21+00:00Answer Link joy |