Jump to content

Combining 2 Xml Files


MarcoKun

Recommended Posts

Hey everyone. I am new to this forums, and very new to XML.I have 2 XML files. One called Parents.xml and the other called Kids.xmlThe parents file consists of approximately 2000 parents, and the kids file consists of approximately 2400 kids.This is one part for a parent. It's in Dutch so please bare with me. The first tag "ouder" means "parent". It consists of tags like firstname, lastname, address, phonenumber, etc.

<ouder><eerste_of_tweede>1 </eerste_of_tweede><nummer>12 </nummer><achternaam>Demirci</achternaam><voorletter></voorletter><adres>Hilledijk 151b</adres><postcode>*example*</postcode><plaats>*example*</plaats><telefoon_privé_1>*example*</telefoon_privé_1><banknummer></banknummer><gironummer></gironummer><deb.nummer>*example*</deb.nummer></ouder>

This is one part a child. The first part "kind" means "child".This also consists of tags like firstname, lastname, address, phonenumber, etc.

<kind><nummer>1.413 </nummer><kindnummer>1 </kindnummer><voornaam>Mohamed</voornaam><voorvoeg></voorvoeg><achternaam></achternaam><contractnummer></contractnummer><adres>Mohamadi</adres><postcode>3071 RB</postcode><plaats>*example*</plaats><geboorte_datum>25 aug 03</geboorte_datum><geslacht>J</geslacht><geplaatste_groep>0 </geplaatste_groep><soort_plaats>PSZ2</soort_plaats><bedrijfsplaats>Nee</bedrijfsplaats><plaatsingsdatum>30 mei 06</plaatsingsdatum><inschrijfdatum>31 jan 07</inschrijfdatum><huisarts>Dr Quaadvlieg</huisarts><ziekenfonds>Zilveren Kruis</ziekenfonds><fondsnummer>*example*</fondsnummer><nationaliteit></nationaliteit><memo></memo><school></school><inentingsprogramma>1 </inentingsprogramma><code>11.111.111.111.111.100.000.000.000.000.000 </code><allochtoon>2 </allochtoon><soort_plaats2></soort_plaats2><percentage_sp1>100 </percentage_sp1><percentage_sp2>0 </percentage_sp2><ouderbijdrage></ouderbijdrage><contractrond>Ja</contractrond><verwachtegeboortedatum>Nee</verwachtegeboortedatum><vrijeinvoer></vrijeinvoer><contracthouder1>0 </contracthouder1><contracthouder2></contracthouder2><bsn>*example*</bsn><isgeplaatstinperiode>Nee</isgeplaatstinperiode><status>De Dam</status><woonwijk>feijenoord</woonwijk><standaardproduct></standaardproduct></kind>

Both the parents and kids file got a tag "nummer" which means "number". When this number is the same for both a kid and a parent, then they are related. How can I link the "nummer" fields so that I can get one output?If there are any questions, please ask.Thanks in advance.Marco

Link to comment
Share on other sites

What you are trying to do is the sort of thing automated by relational-database languages like SQL. PHP does have XML support, but I am not aware of any methods comparable to JOIN or UNION.You can look here for all kinds of XML techniques.It sounds like the data you want to access is pretty basic, so SimpleXML might be the easiest solution. (The syntax is more friendly than true DOM syntax.) You would create a SimpleXML object for each document, and then do some for-looping until you match the node values. (Almost the same as if you were trying to match array values.)I have done similar things with relational elements in a single XML document, and it does not take many lines of code. But if there's a better way, I hope someone jumps in and says so.

Link to comment
Share on other sites

Thanks for your reply Deirdre's Dad.I've been looking at this page you gave me: SimpleXMLAs XML is new to me, PHP is something I never used before, so I don't really know where to start. I thought that you would have to join the <nummer> tags with XSLT, but that I couldn't figure out. Where should I start to even use SimpleXML?Can I get a little upstart? Sorry for the trouble.

Link to comment
Share on other sites

Even though XML can (theoretically) be used as a database, it shouldn't.Yes, you can do what you want with XSLT and/or SimpleXML and/or DOM (btw, if you get used to DOM, SimpleXML will look like "broken" and/or imcomplete to you) and/or XMLReader. That doesn't mean you should use them to emulate a database.I suggest you first Learn PHP (and try it out of course). Ideally, consider using MySQL instead of XML (there is a tutorial for that too). If you're still keen on doing it with XML, I'd reccomend you use XMLReader - it's not as easy to use as SimpleXML (not the first time around at least), but if you have a large dataset, this is the only way to keep the RAM consumption (on the server...) low.

Link to comment
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...