Results 1 to 2 of 2
Jul 18, 2011, 18:46 #1
Selecting specific XML elements...
I have a pretty big XML file structured with the TEI specification and I've been charged with the responsibility of basically migrating the XML into a Drupal installation but in order to do this, I need to extract only specific elements of the XML and simultaneously output these elements into a subsequent XML file for eventual use within Drupal.
Drupal aside for a second, the basic XML structure is as follows:
<TEI.2> <teiHeader> <text> <front> <titlePage></titlePage> <pb/> <div1 tyle="section" n="1" org="uniform" sample="complete"> <head></head> <pb n="xxi"/> <p></p> <p></p> <p></p> <p></p> <p></p> <closer></closer> </div1> <div1> ... </div1> </front> <body> <div1> <head></head> <div2> ...
I tried to parse for what I wanted using the following...
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <head><xsl:apply-templates select="TEI.2/text/front/head"/></head> <p><xsl:apply-templates select="TEI.2/text/front/div1/p"/></p> </xsl:template> </xsl:stylesheet>
So any help from you guys is appreciated as always. How can I parse for only certain elements and save the output as a straight up XML file?
Jul 20, 2011, 01:46 #2
You can have a look at SimpleXML since you know PHP.
To get the head element you would do something like this: