I have an XML document that goes a little something like this:
<marc_field tag="245" label="Title">
Lies will take you somewhere / Sheila Schwartz.
</marc_field>
<marc_field tag="100" label="Personal Author">
Schwartz, Sheila.
</marc_field>
<marc_field tag="020" label="ISBN">
9780979745065
</marc_field>
I want to insert each of these in a separate database entry.
But first, in the "Title," I need to strip off the "/" and everything to the right of it. I am unsure with string command to use. I am trying substr, but that hasn't helped.
But, how to I select "marc_record" fields by their attributes, since these aren't nested elements?
Here is my rather sad attempt:
$xml=simplexml_load_file('marctest.xml') or die ('error: cannot find file.');
//print_r($xml);
foreach ($xml as $addabook) {
db_connect();
$result = mysql_query("insert into node (title, type) values (\"$addabook->substr(marc_field->label=\"Title\", "/"'], "/")\", \"addabook\" )");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Thanks in advance for any sage advice.
spivey