This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > November 2004 > ASP syntax
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Shahid Juma 2004-11-24, 12:19 pm |
| Hi,
If I want to place some ASP syntax, for example Response.write. How can I
achieve that in the XML file? I have an XSL file too...
Thanks, examples would be really great.
Shahid
| |
| Martijn Coppoolse 2004-11-25, 7:15 am |
| Shahid Juma wrote:
> If I want to place some ASP syntax, for example Response.write. How can I
> achieve that in the XML file? I have an XSL file too...
In short: you can't.
You're thinking the wrong way around:
you want to return dynamically generated XML from an ASP page.
To do this, I see two ways:
1. Generate an XML document using MSXML in ASP, e.g.
<%
Dim lxmlDoc, lxmlRootNode
lxmlDoc = Server.CreateObject("Microsoft.XMLDOM")
Set lxmlRootNode = lxmlDoc.createElement("ThisIsTheRootNode")
Set lxmlDoc.documentElement = lxmlRootNode
lxmlRootNode.appendChild(lxmlDoc.createElement("ChildNode")).nodeTypedValue
= "test"
lxmlRootNode.appendChild(lxmlDoc.createElement("KidNode")).nodeTypedValue
= "yell yell nag nag"
Response.ContentType = "text/xml"
lxmlDoc.insertBefore lxmlDoc.createProcessingInstruction("xml", _
"version='1.0' encoding='iso-8859-1'"), _
lxmlDoc.childNodes(0)
lxmlDoc.save Response
%>
(note that you can also use MSXML to transform the XML document using an
XSL stylesheet)
2. Return the XML literally and insert your ASP code using the <% %> as
if you were writing HTML:
<%
Dim lstrDynamicContent
lstrDynamicContent = "yell yell nag nag"
Response.ContentType = "text/xml; charset='ISO-8859-1'"
%>
<?xml version="1.0" encoding="ISO-8859-1"?>
<ThisIsTheRootNode>
<ChildNode>test</ChildNode>
<KidNode><%=lstrDynamicContent%></KidNode>
</ThisIsTheRootNode>
(Note that this is rougly the page generated by the MSXML code above).
The caveat here is that you have to make sure that what you're inserting
is valid in that XML context. Certain characters, like & and ", cannot
be used directly in XML content; they have to be escaped. The advantage
of using the MSXML methods and properties, is that MSXML takes care of
encoding those characters.
I'm not sure if it's safe to use the Server.HTMLEncode(...) function,
since HTML-encoding is not the sames as XML-encoding...
HTH,
--
Martijn <@> Coppoolse <.com>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|