Ok here's the the thing.
I have a flash slideshow which runs from an xml file.
I want to populate the xml file with data from a query, using php
Now I can see on here there are some examples, and I understand some of it, however, in the xml file I am using the 'content' is inside the XML tag rather than wrapped by it.
e.g. this is from an example 开发者_JAVA技巧on here... the tag goes around the data.
<news>
<?
while($item = mysql_fetch_array($data)){
?>
<item>
<url><?=$item['url']; ?></url>
<title><?=$item['title']; ?></title>
</item>
}
?>
</news>
In the XML file I'm using, the tag for a link, looks like this....
<link url="" target=""></link>
So, would the php code go like this
<link url="<?=$item['url]; ?>" target=""></link>
Hope someone can explain !
Thanks
Rich :)
An XML element can contain other elements or text like you have in your example item
with url
and title
. Elements can also have attributes like in HTML <a href="/">Home</a>
.
There are some guidelines when to put "content" into an attribute but we are actually free to do whatever we want as long as the reader of the XML document know if he has to look for another element inside a tag or for the attribute
<link url="www.domain.com" />
// these are equal
<link>
<url>www.domain.com</url>
</link>
// however you have get the url through different process.
Getting attributes is somewhat easier why I think that a lot of documents use attributes. At w3schools are other good examples
Side note: If your element does not contain text or other elements you don't need a closing tag but a slash.
精彩评论