I am trying to load an XML file, and then evaluate 2 different specific tags in the xml and pull the strings into variables.. I am able to get the variables to work but i am unable to do functions that require both variables because something is being written over..
This is where i load the xml file…
$test1 = file_get_contents('testfile1.xml');
$dom = new DOMDocument();
@$dom->loadHTML($test1);
This is where i evaluate the different lines..
//line1
$domx1 = new DOMXPath($dom);
$entries1 = $domx1->evaluate("//dominant_period_sec");
$periodArray = array();
foreach ($entries1 as $entry1) {
$wavePeriod = $entry1->nodeValue;
}
//line2
$domx2 = new DOMXPath($dom);
$entries2 = $domx2->evaluate("//dominant_wind_dir");
$avgwaveHeightArray = array();
foreach ($entries2 as $entry2) {
$waveFeet = $entry2->nodeValue;
}
I’d add this as a comment, because it’s not really an answer, but I don’t have the privs.
If that’s a well-formed XML file, why are you using loadHTML? Why not:
?
I’d guess the answer is:
The variables $wavePeriod and $waveFeet are getting overwritten within the for loops, because you’re overwriting them : ). You could try pushing each item into an array, or something similar – maybe concatenate them. Something like this, maybe?
or