NameSilo

Navigating to LastChild in XML

Spaceship Spaceship
Watch

SGBoise

Established Member
Impact
1
Hey Guys,

I'm trying to find a way to get to <key k_id="4"> using php. I've been trying to get this working all day yesterday and today. Can you guys see what I'm doing wrong?

This is my xml file
Code:
<?xml version="1.0" encoding="utf-8"?>
<keys>
  <key k_id="1">
    <k_id>1</k_id>
    <k_key>_Monkey</k_key>
  </key>
  <key k_id="2">
    <k_id>2</k_id>
    <k_key>_Test</k_key>
  </key>
  <key k_id="3">
    <k_id>3</k_id>
    <k_key>_Hello</k_key>
  </key>
  <key k_id="4">
    <k_id>4</k_id>
    <k_key>_GoodBye</k_key>
  </key>
</keys>


The php code I'm using that's not working.
Code:
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->load("{$this->paths->avs_web}xml/keys.xml");

foreach ($doc->childNodes as $node) {
	$lastelement = $this->get_lastchild($node->lastChild);
	$lastid = (int)$lastelement->getAttribute("k_id");
	$newid = $lastid + 1;
	
}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I don't have any experience with PHP DOM, but $this->get_lastchild($node->lastChild) looks redundant. Get the last child of the last child?
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back