Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML spec has different tag attributes how do I import them to my spec

Status
Not open for further replies.

DD34

IS-IT--Management
Jun 20, 2009
1
ES
Hi, I am a bit of a newbie so please forgive my ignorance but I have a website that imports other peoples data using xml. I need to import a feed that isnt exactly to my spec.
For example
my spec says
<colour>red</colour> and the feed I need to import says

<background>red</background>
I currently have a php script that parses the xml file with the following
if( $xml_current_tag_state == "COLOUR" ) {
$property_data[$property_counter]["colour"] = $property_data[$property_counter]["colour"].$data;
}

How can I get it to import the background field as colour?
Thank you for your help
 
[0] I do not recognize the script lines as validate script lines immediately. Hence, I would just pass on it and propose an xslt solution.

[1] You can use an xslt to transform the original xml document and pass the output for further processing like the one you suggest you're using. The xslt construction is simply an identity transformation adding a specific template to replace background node by color node.
[tt]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[ignore][/ignore]">
<xsl:eek:utput method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="node()" />
</xsl:template>
<xsl:template match="node()|@*|processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="node()|@*|processing-instruction()|comment()" />
</xsl:copy>
</xsl:template>
<!-- adding a specific template to replace background tag by colour -->
<xsl:template match="node()[local-name(.)='background']">
<xsl:element name="colour" namespace="{namespace-uri()}">
<xsl:apply-templates select="node()|@*|processing-instruction()|comment()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>[/tt]
 
The simplest approach would be to just tweak your php:
Code:
if( $xml_current_tag_state == "COLOUR" [red]|| $xml_current_tag_state == "BACKGROUND"[/red] ) {
$property_data[$property_counter]["colour"] = $property_data[$property_counter]["colour"].$data;
}

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top