Click to See Complete Forum and Search --> : Display XML with ASP for news feed


drumbum360
12-08-2010, 01:30 PM
I have an XML file structured like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="style/NewsFeed.css"?>

<updates>
<upd>
<name>Clean</name>
<tdate>11.23.2010</tdate>
<blurb>You have to clean up after yourself in our office.</blurb>
</upd>
<upd>
<name>Welcome</name>
<tdate>11.22.2010</tdate>
<blurb>Welcome message here for all to read!</blurb>
</upd>
</updates>
and am trying to display it in an .asp page with css applied to it. I think I would need the asp to read through the file in a loop that styles all the <name> fields the same and <tdate> fields as well as <blurb> fields. I am not experienced in doing this at all so I'm not sure where to start. I've been reading "parse xml with asp" tutorials a lot lately and cannot seem to get them to work for me with styling elements.
Are you able to help me with this or point me to a post/tutorial that shows how?
Thank you

drumbum360
12-17-2010, 09:35 AM
Anything at all?

itHighway2007
01-13-2011, 11:25 PM
Try following:

set objLst = objXML.getElementsByTagName("upd")

For i = 0 to (objLst.length - 1)

set objChildNodes = objLst.item(i).childNodes

txtName = objLst.item(i).childNodes(0).text

set objChildNodes = Nothing

response.write(txtName)

next


set objXML = Nothing
set objLst = Nothing

Ribeyed
01-19-2011, 11:02 AM
Hi,

There are a few different ways to achieve this. Here is an example:



Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")

If XMLDoc.load(Server.MapPath("/YourXMLFile.xml")) Then
XMLDoc.async = True
if XMLDoc.parseError.errorcode <> 0 then
response.Write "error" & XMLDoc.parseError.url
else
set oXMLNode = XMLDoc.selectNodes("//updates/upd")
response.write "<table>"

For Each node in oXMLNode
response.write "<tr>"
response.write "<td class="tdstyle">" & node.selectNodes("name") & "</td>"
response.write "</tr>"
next
response.write "</table>"

end if


Basic but easy to do.

regards



Ribs
Ribs