Unstoppable Domains

Asp, xml, vbscript

Spaceship Spaceship
Watch

oxford11

Established Member
Impact
4
Question on asp, xml, vbscript - help

I'm retrieving an xml file from the web. It has a doctype which I need to remove or else my xsl can't render the xhtml. I'm trying to use regExp to find doctype and then delete is before my xsl does it's conversion. Below is my code. Any help would be greatly appreciated.

The error I get is:
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'objRegExp.Replace'




<%
'Load the XML

set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load(Server.MapPath("case.xml"))

Dim TextStr
Set TextStr = xml.documentElement

Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<!DOCTYPE(.|\n)+?>"

TextStr = objRegExp.Replace(TextStr, "")

'--------Load the XSL-----------
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("case.xsl"))

Response.Write(TextStr.transformNode(xsl))
%>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Are you sure xml.documentElement is the text of the document and not an object in memory containing that text?
 
0
•••
monaco said:
Are you sure xml.documentElement is the text of the document and not an object in memory containing that text?

Monaco... thanks for taking a look. I've actually gone and changed my code somewhat.

I get the xml document which works. Then I strip out the doctype, that works. I can then display the xml in a browser without the doctype. Everything is great so far. But then I can't figure out how to take the xml that i've stripped the doctype out of and then put it into my stylesheet. Thanks for taking a look... Michael

<%
Response.Buffer = True
Dim objXMLHTTP, xml

' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

' Opens the connection to the remote server.
xml.Open "GET", " case.xml", False

' Actually Sends the request and returns the data:
xml.Send

'Remove DOCTYPE
Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
Dim xmlNoDoctype
xmlNoDoctype = rx.Replace(xml.responseText,"")
Set rx = Nothing

Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Path = Server.MapPath("/uploads/")
FullPath = Path & "\Feed.xml"

Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xmlNoDoctype

'the line below is commented out, but it simply write the xml to the browser without the doctype

'Response.Write xmlNoDoctype

set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("case.xsl"))

' The line below is what's throwing up. I'm not sure if I should be using xmlNoDocType below

Response.Write (xmlNoDocType.transformNode(xsl))

Set xml = Nothing
'Set xsl = Nothing
%>
 
0
•••
Okay, so when you uncomment the line that prints the XML to the browser w/o the doctype, does that part function correctly? Does the XML it spits out parse, and pass a validation or at least a well-formedness check?

If the regex works but the xsl transform does not, the XSL engine may have some trouble transforming it without a doctype. Try modifying the DOCTYPE or replacing it with a line describing the XML version and schema.
 
0
•••
monaco said:
Okay, so when you uncomment the line that prints the XML to the browser w/o the doctype, does that part function correctly? Does the XML it spits out parse, and pass a validation or at least a well-formedness check?

If the regex works but the xsl transform does not, the XSL engine may have some trouble transforming it without a doctype. Try modifying the DOCTYPE or replacing it with a line describing the XML version and schema.


When I uncomment that line, the xml prints to the browser without the doctype. That works. xml validates. I've downloaded the xml file and actually removed the doctype and the xsl transformed it fine. But when I use the regexp, remove the doctype, I get an error:

Microsoft VBScript runtime error '800a01a8'

Object required: '<?xml version="1.0" '


Which happens at the line in
Response.Write (xmlNoDoctype.transformNode(xsl))

Thanks for helping out here! Michael
 
0
•••
I'm wondering if the transform isn't a valid action for a string...you may need to instantiate a new xml node object and set its innerHTML (or equivalent) property to the actual xml, *then* try to transform it.
 
0
•••
monaco said:
I'm wondering if the transform isn't a valid action for a string...you may need to instantiate a new xml node object and set its innerHTML (or equivalent) property to the actual xml, *then* try to transform it.


do you have code that could help guide me by any chance? :)
 
0
•••
Sorry, not in VBScript. I do have some old code for a similar thing I did in PHP, but since you aren't using PHP, it probably won't help at all :/
 
0
•••
monaco said:
Sorry, not in VBScript. I do have some old code for a similar thing I did in PHP, but since you aren't using PHP, it probably won't help at all :/


If you have a php that does what I'm looking for, I'll jump ship in a heart beat. There's no loyalty here! :)
 
0
•••
Let me see if I can dig up the code...I used to maintain my news section in RSS format and use an XSL to generate the page, but that was several site rewrites ago. As I recall it was really simple though.

To get you started, here's the section of the php manual on xsl: http://us.php.net/xsl
Here's the section on regex-based text replacement: http://us.php.net/manual/en/function.preg-replace.php
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back