Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Import values from XML file
November 30, 2011, 11:30 pm
rate this thread
<?xml version="1.0" encoding="UTF-8"?>
<riga IdAA="1" DesBB="Eliminazione" />
<riga IdAA="2" DesBB="Controllo" />
can you tell me how can I save each row in my DB?
I don't know how to create a function for read all values and save in
- Robert Maas, http://tinyurl.com/uh3t
March 27, 2012, 5:26 pm
Re: Import values from XML file
I agree, with one additional suggestion later below.
Note that for this purpose of reading an existing XML file, most of
that manual can be ignored. All you need are the methods to tell
the children of a given node, and the type and (text) contents of
each node. All the modification methods are moot to your needs.
Now here's my additional suggestion: The XML DOM parser merely
validates that the file is valid XML, and converts it into a parse
tree. It doesn't verify that the structure (tree = DOM) matches
what you expect for your application. IMO it's dangerous to
traverse the tree node by node, copying data directly into DB rows,
because if there's any mistake in the XML, you've already blindly
copied earlier data into tables and thus have a table that isn't
completely updated, i.e. is an inconsistent mess. So what I do
instead is to validate the *entire* DOM node by node, copying all
the data into a tree o nested associative array. If I discover a
mistake in the structure after I've built part of the tree, no
trouble, I "die" and the nested associative array is discarded, and
the DB table is left exactly as it was at the start. If the
validation process runs to completion, then I know the tree is
entirely correct, and *then* I can copy the data from the nested
associative array into the DB tables, after which the DB tables
will again be in a consistent state.
It's an extra step the way I do it, but I believe it's safer.
But it's your choice whether you do that or not.
- — Next thread in » PHP Scripting Forum