Hello again.
I've not been on this thread as I have been trying for a while to try and resolve this using the information given and some more reseach, but I just can't seem to get it done. My working knowledge of PHP is limited, but I have had success parsing simpler XML streams in the past.
Back to the original question...
Out of respect to the people helping me, I have put together an example which I hope will be clearer.
This is the basic structure of the XML (with dashes so it displays better here and is easier to read): -
<LIBRARY>
------<CATALOGUE>
------------<BOOK TITLE="NEW ITALIAN CUISINE">
------------------<CHAPTER ID="4" NAME="MAIN COURSES" PAGECOUNT="65">
------------------<CHAPTER ID="2" NAME="GETTING STARTED" PAGECOUNT="14">
------------------<CHAPTER ID="1" NAME="INTRODUCTION" PAGECOUNT="23">
------------------<CHAPTER ID="3" NAME="SIMPLE STARTERS" PAGECOUNT="56">
------------</BOOK>
------------<BOOK TITLE="NEW GREEK CUISINE">
------------------<CHAPTER ID="1" NAME="INTRODUCTION" PAGECOUNT="56">
------------------<CHAPTER ID="3" NAME="SIMPLE STARTERS" PAGECOUNT="59">
------------------<CHAPTER ID="4" NAME="MAIN COURSES" PAGECOUNT="12">
------------------<CHAPTER ID="2" NAME="GETTING STARTED" PAGECOUNT="18">
------------</BOOK>
------------<BOOK TITLE="NEW FRENCH CUISINE">
------------------<CHAPTER ID="2" NAME="GETTING STARTED" PAGECOUNT="23">
------------------<CHAPTER ID="3" NAME="SIMPLE STARTERS" PAGECOUNT="56">
------------------<CHAPTER ID="4" NAME="MAIN COURSES" PAGECOUNT="64">
------------------<CHAPTER ID="1" NAME="INTRODUCTION" PAGECOUNT="17">
------------</BOOK>
------</CATALOGUE>
</LIBRARY>
What I am looking to do is create a script that will return the name of the book, and also the number of pages in each chapter, given that each chapter the criteria of:
ID="1", NAME="INTRODUCTION"
ID="2", NAME="GETTING STARTED"
ID="3", NAME="SIMPLE STARTERS"
ID="4", NAME="MAIN COURSES"
... as all of them do in the above example. However, I can't simply use CHAPTER[0], CHAPTER[1] etc as the chapter numbers are not in order. I am basically just using this as an example of how I can navigate and parse XML based on the attributes.
The aim will be to send it to a MySQL database. The code for that, I have done OK. It's the creation of the array based on the criteria above I having trouble understanding.
So far, I just have this basic outline: -
<?php
$Library = simplexml_load_file('catalogue.xml');
foreach ($Library->CATALOGUE->xpath('//BOOK') as $Book) {
$bookarray = array (
$Booktitle = $Book['TITLE'],
$Chapter1pagecount = ???????????????,
$Chapter2pagecount = ???????????????,
$Chapter3pagecount = ???????????????,
$Chapter4pagecount = ???????????????);
}
?>
I am just simply stuck at how to get those attributes to parse OK.
Anyway... sorry to bother you all again... but this is ssssooooo frustrating!!!