|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Populating <img> and <a> tags with XML?
My question: I'm using a HTML page to call an XML file (I know - I should use XSL... but I can't because I my file has to be a .html file... don't ask) and the only thing I can't get to work are the <img> and <a> tags.
I'm using <div datafld="xxx" /> for other fields and that's working fine - but I'm stuck on getting the <img src> to display the image and the <a> tag getting the URL from my xml file to the href (or similiar) attribute. Thanks in advance- Matt html code: <xml id="xmldso" src="file.xml"></xml> <table datasrc="#xmldso"> <tr> <td> <img datafld="imagepath"> <a datafld="URL" href="" /> </td> </tr> </table> xml example: <deal> <title>xxx</title> <company>yyy</company> <imagepath>images/devshedlogo.jpg</imagepath> <URL>http://www.devshed.com</URL> </deal> |
|
#2
|
||||
|
||||
|
I didn't know that you could obtain information from an XML document using strictly HTML. This seems wrong. Has anyone else ever seen this or know if something like this will work?
The only solution like this I know of is using JavaScript to read in the XML document and then using it to parse, read and then set values in the HTML. |
|
#3
|
||||
|
||||
|
It's a Microsoft only "standard" :-) Apparently the <xml> tag only works in IE 5.0 and above, and isn't part of any standardised specification. It's an html tag, not an xml tag.
W3Schools gives this short demo which I managed to get working: <html> <body> <xml id="cdcat" src="cd_catalog.xml"></xml> <table border="1" datasrc="#cdcat"> <tr> <td><span datafld="ARTIST"></span></td> <td><span datafld="TITLE"></span></td> </tr> </table> </body> </html> mwilson, i've used something similar: <xml src="photoalbum.xml" id="xmldso" async="false"></xml> ... <p> Title: <span datasrc="#xmldso" datafld="TITLE"></span> </p> <p> Description<br /> <span datasrc="#xmldso" datafld="DESCRIPTION"></span> </p> <a datasrc="#xmldso" datafld="IMAGE" target="_blank"> <img alt="Click For Large Version" datasrc="#xmldso" datafld="THUMBNAIL" border="0"></img> </a> maybe you could try <img alt="My Picture" datasrc="#xmldso" datafld="imagepath" border="0"></img> instead of having the datasrc in the table tag? Hope this helps, - I'm new to all this as well :-) Jamie.
__________________
Practise Random Kindness |
|
#4
|
|||
|
|||
|
Quote:
Thanks Matt... do you have a JS func for the solution you mentioned? I'd hate to just use the <xml> tag and alienate all our non-IE users. Thanks again all- |
|
#5
|
||||
|
||||
|
I believe that even the JavaScript solution would be for IE users only because you would have to create a Microsoft.XMLDOM ActiveX object.
I believe that Mozilla based browsers may be able to do the same thing (not with ActiveX, but read in an XML document with a plug-in perhaps), but I am unsure on how to do this and you would have to start incorporating brower sniffing which I am against. I hope that someone else can help you. Matt |
|
#6
|
|||
|
|||
|
Don't worry, you CAN use XSL!
Matt, about this:
Quote:
It is common for free web service providers like GeoCities to restrict the naming of files (that have certian HTML tags) alowed on their servers to .html or .htm extensions. However, there is good news (hopefully in your case). You do not need to name your .xsl stylesheet with a .xls extension. You can use .txt as long as it is still internally identified a xsl stylesheet doctype with the usual W3C standard declaration tags that are placed at the top of the file. Example of what to have at the top of your .txt XSL stylesheet named "home_stylesheet.txt" in a subdirectory (relative to the location of your XML file) that I named "resources": Code:
<?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="/"> <?xml version="1.0"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> </title> <link rel="stylesheet" type="text/css" href="resources/global_stylesheet.css" /> </head> <body> ... Example of what to have at the top of your .xml XML file (named "home.xml"): Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="resources/home_stylesheet.txt"?> <root> <general> <title> Home </title> </general> </root> Sorry this is a few days late -- I just signed up here today. I really hope you can use this to format your XML data through a XLS stylesheet like you probably would like, instead of a regular HTML document. Also, you should upgrade your HTMLs to XHTMLs if you want to use either XLS or XML. If you don't know how XHTML differs from HTML, you can always go to the W3Schools XHTML tutorial page or download this Windows GUI version of Dave Raggett's HTML Tidy program from W3C, which parses your the HTML and, based on your preferences, will convert it to XHTML. Good luck! Latrosicarius |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Populating <img> and <a> tags with XML? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|