Hello there,
I'm trying to decide what the best way is to parse some XML templates I've developed. The idea is that these XML templates will be parsed and the data will be imported into a database (a CMS system I've developed)
Now, I could do preg matching and do a bunch of nested loops. But I'm not so sure that is the best thing to do.
I'm actually looking into PHP's XML functions, because I think they would be more extensible and flexible, but I'm a little lost. I really don't understand what I'm doing with them.
Suppose I have the following XML code:
<section>
<article>
<title>Headline</title>
<slideshow>
<photo src="file1.jpg">Caption</photo>
<photo src="file2.jpg">Caption</photo>
<photo src="file3.jpg">Caption</photo>
</slideshow>
<body>
<p>para 1</p>
<p>para 2</p>
</body>
</article>
<article>
<title>Headline</title>
<slideshow>
<photo src="file1.jpg">Caption</photo>
<photo src="file2.jpg">Caption</photo>
<photo src="file3.jpg">Caption</photo>
</slideshow>
<body>
<p>para 1</p>
<p>para 2</p>
</body>
</article>
</section>
Assuming I want to extract the headline, photo file name (src) and caption (assuming there could be no photos or many photos, as well as paragraph content, how would you go about it? Or would you stick with a preg approach?
What would all of you suggest?