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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML REDIRECT OR DISPLAY

Status
Not open for further replies.

Kazzy

Programmer
Jul 21, 2003
20
US
Help...help I am new to xml.I am getting some xml files from a data-feed. Some of the xml documents contains a link under the <item-content>. some others contain <html> tag (see sample below). I need to be able to redirect the page to the webaddress provided inside of the <item-content> tag OR just display content if <item_content> contains and <html> tag. In other words if user click to open the page. It must redirect to webaddress provided or display content if xml file contains an <html> tag.


Thanks,

SOME OF THE XML FILES LOOKS LIKE THE FOLLOWING

---------sample 1-------------
<?xml version="1.0"?>
<!DOCTYPE SEND_ITEM_DETAILS>
<LIFE>
<item>
<item-id>9396</item-id>
<item-content> Group&SESSION=6767530564965005</item-content>
</item>
</life>

------- Sample 2 ------------------------------------

<?xml version="1.0"?>
<!DOCTYPE SEND_ITEM_DETAILS>
<LIFE>
<item>
<item-id>11989</item-id>
<item-content>
<html>
<head>
<title>Relapse</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h4>
<font face="Arial, Helvetica, sans-serif" color="#324987">Question: When is
the most typical time that most smokers relapse when they try to stop?</font>
</h4>
<p><font face="Arial, Helvetica, sans-serif" size="2">The majority of smokers
relapse in the first few days (days 1-3). </font>
</p>
</body>
</html>
</item-content>
</item>
</life>
 
Not enough info. What technologies you using? What does the user click on?

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
I am using ASP. I created a asp page that parse and display the xml content (i call it the main xml file). This xml page contains <item-id> tags. The tags refers/points to another xml file (sample1 and sample2 etc). When user click on a link on the main page. a popup window opens (getItem.asp is call see below). The user needs to be redirect if the content of the xml file contais the <item-content> tag with web address (sample1) or display content if <item-content> tags contains the <html> tag (sample2). My problem is on the getItem.asp

Any suggestion will be great.

Again need a lot of help...I hope you understand what I am trying to do. thanks


----- main.asp ------------------------------------------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/dbConn.asp" -->
<%
Dim aspPage
Dim xmlFile
Dim xslFile
aspPage= "main.asp"
xmlFile = "main.xml"
xslFile = "getXSL.xsl"
%>

<script language="JavaScript" type="text/JavaScript">
<!--
function openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<%
function showxmldata(strMXLFile, strXSLFile, strParam)
dim blnXMLOK
dim blnXSLOK
dim strFilesErr

Set xmlDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDoc.preserveWhiteSpace = true
blnXMLOK = xmlDoc.load(Server.MapPath(strMXLFile))
blnXSLOK = xslDoc.load(Server.MapPath(strXSLFile))


if blnXMLOK and blnXSLOK then
'check for parameter
if strParam <> "" then
set xslt = Server.CreateObject("MSXML2.XSLTemplate")
set xslt.stylesheet = xslDoc
Set xslProc = xslt.createProcessor()
xslProc.input = xmlDoc
xslProc.addParameter "strCategory", cstr(strParam)
xslProc.transform
sOutput = xslProc.output
response.Write(sOutput)
set xslProc = nothing
set xslt = nothing

else
response.Write(xmlDoc.transformNode(xslDoc))

end if


else
if not blnXMLOK then
strFileErr = strFileErr & "strXMLFile: " & strMXLFile
end if
if not blnXSLOK then
strFileErr = "<br>" & strFileErr & "strXSLFile: " & strXSLFile
end if
response.write(strFileErr)
End if

set xmlDoc = nothing
set xslDoc = nothing

End Function
%>


<html>
<head>
</head>
<Body>
<%
Dim objXMLDoc
Set objXMLDoc=Server.CreateObject("MSXML2.DOMDocument")
objXMLDoc.load(Server.MapPath(xmlFile))

if objXMLDoc.parseError.errorcode<>0 then
'error handling code
Response.write "Error code: " & objXMLDoc.parseError.errorCode & "<BR>"
Response.write "Position in file: " & objXMLDoc.parseError.filepos & "<BR>"
Response.write "Error text: " & objXMLDoc.parseError.reason & "<BR>"
else


Dim vMXLFile, vXSLFile, vParam

vMXLFile = xmlFile
vXSLFile = xslFile

if request.QueryString("strMenu")="" then
vParam = "Addictions Articles"
else
vParam = request.QueryString("strMenu")
end if

showxmldata vMXLFile, vXSLFile, vParam
end if
%>
</body>
</html>

----- main.xml ------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<LIFE>
<DATAAREA>
<folder>
<folder-name>Addictions</folder-name>

<category>
<category-name>Addictions Articles</category-name>
<category-items>
<item-name>Stages of Recovery</item-name>
<item-description>In this article you will learn about the stages people go through to recover from drug or alcohol abuse and some resources that can help you learn more.</item-description>
<item-id>sample1</item-id>
</category-items>

<category-items>
<item-name>Lapse without Relapse</item-name>
<item-description>In this article you will learn about the basics of relapse prevention, situations that can contribute to relapse, and where to begin to get help.</item-description>
<item-id>sample2</item-id>
</category-items>
<category-items>
<item-name>The Effects of Alcohol on You and Your Workplace</item-name>
<item-description>In this article you will learn about the effects of alcohol on the workplace and what you can do about it.</item-description>
<item-id>11972</item-id>
</category-items>
</category>

<category>
<category-name>Addictions Frequently Asked Questions</category-name>
<category-items>
<item-name>When do most smokers relapse when they try to stop?</item-name>
<item-description>null</item-description>
<item-id>11989</item-id>
</category-items>
<category-items>
<item-name>Is a slip involving just one cigarette serious?</item-name>
<item-description>null</item-description>
<item-id>11997</item-id>
</category-items>
</category>

<category>
<category-name>Addictions Announcements</category-name>
</category>
</folder>
</DATAAREA>
</LIFE>

------ getXSL.xsl ---------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" indent="yes" doctype-system="../dtds/docbookx.dtd" doctype-public="-//OASIS//DTD DocBook XML//EN"/>
<xsl:param name="strCategory"/>
<xsl:template match="LIFE/DATAAREA/folder/category">
<xsl:value-of select="child::folder-name"/>
<xsl:if test="category-name = $strCategory">
<div class="tbl-heading"><p style="width:80%;font-weight:bold"><xsl:value-of select="child::category-name"/></p></div>
<xsl:for-each select="category-items">
<xsl:variable name="itemid">
<xsl:apply-templates select="child::item-id"/>
</xsl:variable>
<xsl:variable name="itemName">
<xsl:apply-templates select="child::item-name"/>
</xsl:variable>
<br/>
<div><a class="body_Link" title="{$itemName}" href="javascript:;" onclick="openBrWindow('getItem.asp?item={$itemid}.xml','xx','width=700,height=600 scrollbars=yes location=yes');"><b><xsl:apply-templates select="child::item-name"/> </b></a></div>
<div>
<xsl:variable name="include_description" select="boolean(child::item-description[.!='null'])"/>
<xsl:if test="child::item-description=$include_description">
<xsl:value-of select="child::item-description"/>
</xsl:if><br/></div>
<div> </div>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


---------- getItem.asp ----------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim vItem
vItem = request.QueryString("item")

Dim objXMLDoc, xmlFile
xmlFile = vItem

Dim objSvrHTTP
Dim PostData

Set objSvrHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
objSvrHTTP.open "GET", xmlFile, false

objSvrHTTP.send
Response.Write objSvrHTTP.responseText
response.end



Set objXMLDoc=Server.CreateObject("MSXML2.DOMDocument")
objXMLDoc.load(Server.MapPath(xmlFile))


if objXMLDoc.parseError.errorcode<>0 then
'error handling code
Response.write "Error code: " & objXMLDoc.parseError.errorCode & "<BR>"
Response.write "Position in file: " & objXMLDoc.parseError.filepos & "<BR>"
Response.write "Error text: " & objXMLDoc.parseError.reason & "<BR>"
else
' proceed
Dim tempMenu
tempMenu = ""
set oRoot = objXMLDoc.documentElement
Set NodeList = oRoot.getElementsByTagName("item-content")
'Set NodeListn = oRoot.nodeName
For Each Elem In NodeList
'If (Elem.firstChild.nodeValue = "Addictions articles") then
isNode = Elem.nodeName
xElment =Elem.text
response.redirect(xElment)
If isNode = "html" then
response.Redirect("testxmlhttp.asp?item=" & vItem)
Else
'xElment =Elem.text
'response.Write(xElment)
End if
Next
End if
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top