我在一个名为'artists'的drupal站点上有节点我使用模块将所有这些节点导出到xml文档中。 代码如下所示:
<node>
<vid>304</vid>
<uid>102</uid>
<title>Hanne Hoejfeldt</title>
<log></log>
<status>1</status>
<comment>2</comment>
<promote>0</promote>
<sticky>0</sticky>
<vuuid>060c67ab-fea1-484e-9a5b-f551840d48b1</vuuid>
<ds_switch></ds_switch>
<nid>304</nid>
<type>artist</type>
<language>und</language>
<created>1352825291</created>
<changed>1438587438</changed>
<tnid>0</tnid>
<translate>0</translate>
<uuid>03eb47d0-fb45-4ad5-bde2-0c5b762d8506</uuid>
<revision_timestamp>1438587438</revision_timestamp>
<revision_uid>11</revision_uid>
<body>
<und _numeric_keys="1">
<n0>
<value><p><span style="font-family: Arial, sans-serif; line-height: 1.538em;">Hanne Hoejfeldt was born in 1949 in Hjorring, Denmark.</span></p><p style="margin-bottom: 0in"><b style="line-height: 1.538em; font-family: Arial, sans-serif;">Solo Exhibitions</b></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">1994 Pandrup Town Hall, Pandrup, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2006 Nibe Museum, Nibe, Denmark</font></p><p style="margin-bottom: 0in">&nbsp;</p><p style="margin-bottom: 0in"><font face="Arial, sans-serif"><b>Group Exhibitions</b></font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">1997 Billedstedet, Fosdalen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">1998 Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Kirsten Kjaers Museum of Art, Frostrup, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark </font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">1999 Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery SO-TO, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Danish Art-Fair, Viborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2000 Gallery Knud Grothe, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Billedstedet, Fosdalen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2001 Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Bronderslev Highschool, Bronderslev, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2002 Gallery Knud Grothe, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Billedstedet, Fosdalen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2003 Gallery Knud Grothe, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark </font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Jarsbo, Aarthus, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Artgallery Odense, Odense, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Varmegalleriet, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2004 Artgallery Odense, Odense, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2005 Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Billedstedet, Fosdalen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Fussingo Castle, Fussingo, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark </font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Jarsbo, Aarthus, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galerie Horn, Lolland, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Vejle, Vejle, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Artgallery Odense, Odense, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2006 Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Jarsbo, Aarthus, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Copenhagen, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2007 Gallery Knud Grothe, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Jarsbo, Aarthus, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Copenhagen, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galerie Horn, Lolland, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2008 Gallery Knud Grothe, Copenhagen, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Fyns Arthouse, Ringe, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Jarsbo, Aarthus, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Inuit, Aalborg, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Gilberg, Fredericia, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Artgallery Odense, Odense, Denmark</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Gallery Annorlunda, xxxx, Sweden</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">GINA Gallery of International Na Art, Tel Aviv, Israel</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">2009 Fete de L&#39;Art Naif, Verneuil, Paris, France</font></p><p style="margin-bottom: 0in"><font face="Arial, sans-serif">Katowice Festival, Katowice, Poland</font></p><p style="text-indent: 0.5in; margin-bottom: 0in"><font face="Arial, sans-serif">Magdeburg Festival, Magdeburg, Germany</font></p><p style="text-indent: 0.5in; margin-bottom: 0in"><font face="Arial, sans-serif">Galleri Gilberg, Fredericia, Denmark</font></p></value>
<summary></summary>
<format>full_html</format>
</n0>
</und>
</body>
<field_profile_photo>
<und _numeric_keys="1">
<n0>
<fid>1166</fid>
<uid>1</uid>
**<filename>Hanne_Hoejfeldt.jpg</filename>**
<uri>public://Hanne_Hoejfeldt.jpg</uri>
<filemime>image/jpeg</filemime>
<filesize>6406</filesize>
<status>1</status>
<timestamp>1360494813</timestamp>
<type>image</type>
<uuid>8f0d8a1c-721c-47eb-b237-01c4b76f55a1</uuid>
<field_file_image_alt_text _numeric_keys="1"></field_file_image_alt_text>
<field_file_image_title_text _numeric_keys="1"></field_file_image_title_text>
<rdf_mapping _numeric_keys="1"></rdf_mapping>
<image_dimensions>
<width>140</width>
<height>140</height>
</image_dimensions>
<alt>Hanne Hoejfeldt</alt>
<title>Hanne Hoejfeldt</title>
<width>140</width>
<height>140</height>
</n0>
</und>
</field_profile_photo>
<field_country>
<und _numeric_keys="1">
<n0>
<lid>199</lid>
<name></name>
<street></street>
<additional></additional>
<city></city>
<province></province>
<postal_code></postal_code>
<country>dk</country>
<latitude>0.000000</latitude>
<longitude>0.000000</longitude>
<source>0</source>
<is_primary>0</is_primary>
<province_name></province_name>
**<country_name>Denmark</country_name>**
<fax></fax>
<phone></phone>
</n0>
</und>
</field_country>
<field_country_location>
<und _numeric_keys="1">
<n0>
<nid>1528</nid>
</n0>
</und>
</field_country_location>
<field_first_name_artist>
<und _numeric_keys="1">
<n0>
**<value>Hanne</value>**
<format type="NULL"></format>
<safe_value>Hanne</safe_value>
</n0>
</und>
</field_first_name_artist>
<field_last_name_artist>
<und _numeric_keys="1">
<n0>
<**value>Hoejfeldt</value>**
但是我只想要标签内的值
<title>Hanne Hoejfeldt</title>, <value><p><span style="font-family: Arial, sans-serif; line-height: 1.538em;">Hanne Hoejfeldt was born in 1949 in Hjorring, Denmark.</span></p><... </value>, <filename>Hanne_Hoejfeldt.jpg</filename>, <country_name>Denmark</country_name>, <value>Hanne</value, <value>Hoejfeldt</value>
如何从xml文件中仅提取这些值?
答案 0 :(得分:0)
将一个XML转换为另一个XML是XSLT的自然任务。例如,使用XSLT 2.0:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<!-- create one root element,
and process elements in the source XML as content of the root -->
<xsl:template match="/">
<root>
<xsl:apply-templates select="*"/>
</root>
</xsl:template>
<!-- copy required elements -->
<xsl:template match="*[name()=('title','value','filename','country_name')]">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<!-- remove unnecessary elements -->
<xsl:template match="*">
<xsl:apply-templates select="*"/>
</xsl:template>
</xsl:transform>
<强> Demo
强>
答案 1 :(得分:0)
使用XML Linq
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<div ng-app='app' ng-controller='myController'>
<div id="locationField">
<input id="autocomplete" placeholder="Enter your address" type="text">
</div>
<table id="address">
<tr>
<td class="label">Street address</td>
<td class="slimField">
<input ng-model="formData.street_number" class="field" id="street_number" disabled="true" type="text">
</td>
<td class="wideField" colspan="2">
<input ng-model="formData.route" class="field" id="route" disabled="true">
</td>
</tr>
<tr>
<td class="label">City</td>
<td class="wideField" colspan="3">
<input ng-model="formData.locality" class="field" id="locality" disabled="true">
</td>
</tr>
<tr>
<td class="label">State</td>
<td class="slimField">
<input ng-model="formData.administrative_area_level_1" class="field" id="administrative_area_level_1" disabled="true">
</td>
<td class="label">Zip code</td>
<td class="wideField">
<input ng-model="formData.postal_code" class="field" id="postal_code" disabled="true">
</td>
</tr>
<tr>
<td class="label">Country</td>
<td class="wideField" colspan="3">
<input ng-model="formData.country" class="field" id="country" disabled="true">
</td>
</tr>
</table>
<pre>{{ formData | json }}</pre>
<pre>{{ ll | json }}</pre>
</div>