View Full Version : Modifying Processing Line Done, but wrong way

09-27-2002, 05:14 AM
I've a problem now. I noticed i've programmed the wrong thing.

My ASP Script(part of it)

XMLfilesrc = Request.Form("xmlfileid")
XSLfilesrc = Request.Form("xslfileid")

'Creating a NodeList of the elements in the XML Tree
Set objNodeList = objDom.documentElement.childNodes

'Loop through each item in the NodeList and check if its NodeType is that of a Processing Instruction i.e.
Dim hrefsrc
hrefsrc="href=""" &XSLFilesrc +""""

for i = 0 to objNodeList.length-1
If objNodeList.item(i).nodeType = 7 then
set objNewPI = objDom.createProcessingInstruction("xml-stylesheet"," ")
objdom.documentElement.appendchild objnewpi
objNewPI.data = "type=""text/xsl"" " +hrefsrc
' objdom.documentElement.replaceChild objNewPI, objNodeList.item(i)
objdom.documentElement.replaceChild objNewPI, objDOM.childNodes(0)

End If

This works perfectly and it does modify the processing line my xml file. But This only modify the processing instruction in the element node list. (which is in <text></text>

(XML that is modifled)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="aflooding.xsl"?>
<title>Adaptive Flooding</title>
<s-title>Adaptive Flooding</s-title>

What i wanted was to put it after <?xml version="1.0">
so that i can run the xml file which will display according to the stylesheet after i use this asp to modify. Because currently it is inside <text></text> which i can output it with explorer just by double clicking. I've no idea how to do it out of the element list. Hope anyone can answer me..

Alex Vincent
09-28-2002, 02:48 AM
I think I can help you.

You currently write:

objdom.documentElement.replaceChild objNewPI, objDOM.childNodes(0)

I take it objdom is the document node. In that case, you can write:

objdom.insertBefore(objNewPI, objdom.documentElement)

That should work. Of course, I've never coded ASP before. ;)