Reply to Re: xml to sql?

Your name:

Reply:


Posted by Michael Trausch on 10/13/43 11:36

NC wrote:
[snip]
>
> Note that there are two <item> entities, but they contain completely
> different data fields. Moreover, XML can contain entities within
> entities, whereas databases cannot contain records within records...
>
> This problem can be solved only if the XML structure can be directly
> mapped onto a database...
>

It is possible depending on the back-end DB server. If you were using
something that supported row-like types for a field, you could manage to
make such a thing happen. It would be pretty complex though, and it
would require the logic to be smart enough to know when the DB
infrastructure existed to do such a thing.

If you're using a very tightly controlled source for the XML, you could
(in theory) use any of the XML parsing libraries or classes that are out
there, or try using PHP's built-in XML items. I have not yet used any
of these things myself, but if you have the tightly controlled XML
already, then you could pull the nodes that you know that you want to
populate the database with, and do something like (warning: pseudo-code):

---------
for each xml_node("item")
{
$sql = "INSERT INTO table (xx, yy, zz) VALUES ('";
$sql .= db_system_escape_string(xml_node("./xx"));
$sql .= "', '";
$sql .= db_system_escape_string(xml_node("./yy"));
$sql .= "', '";
$sql .= db_system_escape_string(xml_node("./zz"));
$sql .= "')";

db_system_execute_query($sql);
}
----------

That would be, however, harder in practice to implement then the
pseudo-code you see above. The logic of it would be simple: Iterate
over every <item> ... </item> node and extract the interesting data.
This makes broad assumptions about the XML that is coming in, however,
and since any well-formed XML document can be parsed, figuring out how
to regulate all of that is up to the OP.

Best wishes,
Mike

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация