Hi,
Im trying to parse quite a large xml file(80kb). My situation dictates that i must use the DOM XML method. Im new to this method.
The majority of documentation i have found online and in books explains how to extract the entire content of of the XML document, but not how to extract a single attribute of a specified element.
I have tried to work my way around this but to no avail. I have managed to use the xmldocfile() function to sucessfully parse the file, but im having trouble getting to the information i need.
This is what i have at the moment:
$root = $doc->document_element(); // Gets the root element.
$plot_region = $root->child_nodes(); // Then locate the <harmonic> elements.
$plot_region = $plot_region->first_child(); // ...
$sphere_plot = $plot_region->child_nodes(); // ...
$sphere_plot = $sphere_plot->first_child(); // ...
$plot_harmonics = $sphere_plot->child_nodes(); // ...
$plot_harmonics = $plot_harmonics->last_child(); // ...
$harmonics = $plot_harmonics->child_nodes(); // found here.
The following is a small section of the XML file i want, and shows the data that im trying to get at.
- <field_plot base_field="0.00000000000" unit="T">
- <plot_region>
- <sphere_plot radius="0.00">
+ <plot_points angle_type="gaussian" unit="x" nplanes="00" npoints="00">
- <plot_harmonics unit="ppm" lnorm="0" radius="0.00">
<harmonic n="0" m="0" a_value="000.000" b_value="0." />
<harmonic n="1" m="0" a_value="00.00000" b_value="0." />
...
...
The idea was that i use the above php code to navigate the parsed xml file to the elements that i want (that is the <harmonic> elements....) and then i use a foreach loop to conditionally check each element to see if it has the value i need.
I'm hoping some of you already know this, ... but it doesnt work. The reason why is because when i try to do this:
$plot_region = $plot_region->first_child();
i am trying to access member function on a non-object (that is that $plot_region is not an object, but rather an array of objects)
I have tried accessing the individual array objects, but it doesnt seem to work....can anyone point me in the right direction...
TYIA
Pile