doctype

R

Roland Hall

I'm having a really tough time finding references for XML with ASP.
Everything I find assumes I already have an XML file and want to display it
with ASP. I'm looking for reference material where I can CREATE XML files
using ASP.

Currently I am looking for a way to put in the following line in an XML file
using ASP.

<!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>

I can add

<?xml version="1.0" encoding="ISO-8859-1"?>

using...

set pi = objXML.createProcessingInstruction("xml", "version='1.0'
encoding='ISO-8859-1'")
objXML.insertBefore pi, objXML.firstChild

and...

<?xml-stylesheet type='text/xsl' href='freight.xsl'?>

using...

set pi2 = objXML.createProcessingInstruction("xml-stylesheet",
"type='text/xsl' href='freight.xsl'")
objXML.insertBefore pi2, objXML.firstChild

but I cannot find a way to include:
<!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>

I tried using:

dim node
set node = objXML.createTextNode("<!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>")
objXML.insertBefore node, objXML.firstChild

but I get an error:
msxml4.dll error '80004005'
This operation can not be performed with a Node of type PCDATA.

/dev/freight2.asp, line 55

Apparently MSFT seems to think nobody uses VBScript in ASP to work with XML.
All examples are in JScript and they give you a guideline of how to convert
examples/syntax but still nothing re: doctype. The info only tells you how
to use it to OBTAIN doctype info from an existing XML file.

Since I have no references, I thought I'd try something else:

objXML.doctype = "<!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>"

but I get an errror:

Wrong number of arguments or invalid property assignment: 'objXML.doctype'

I'm betting the latter since I believe using it this way is read-only.

If someone could just point me to a reference with all commands with
vbscript syntax, I'd forever be appreciative.

TIA...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
M

Martin Honnen

Roland Hall wrote:

Currently I am looking for a way to put in the following line in an XML file
using ASP.

<!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>

Well using the MSXML APIs doesn't depend on whether you do it in ASP
and/or with VBScript or JScript or VB.
When you create a new document from scratch then the only way I have
found to add a DOCTYPE declaration is to use the loadXML to load the
DOCTYPE declaration and the root element e.g.
Dim XmlDocument1, XmlDocument2, XmlSource
Set XmlDocument1 = Server.CreateObject("Msxml2.DOMDocument.3.0")
XmlSource = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
"<!DOCTYPE FREIGHT SYSTEM ""test2004123001.dtd"">" &
vbCrLf & _
"<FREIGHT />"
XmlDocument1.validateOnParse = False
XmlDocument1.loadXML(XmlSource)
 
R

Roland Hall

:
:
: Roland Hall wrote:
:
:
: > Currently I am looking for a way to put in the following line in an XML
file
: > using ASP.
: >
: > <!DOCTYPE FREIGHT SYSTEM 'freight.dtd'>
:
: Well using the MSXML APIs doesn't depend on whether you do it in ASP
: and/or with VBScript or JScript or VB.
: When you create a new document from scratch then the only way I have
: found to add a DOCTYPE declaration is to use the loadXML to load the
: DOCTYPE declaration and the root element e.g.
: Dim XmlDocument1, XmlDocument2, XmlSource
: Set XmlDocument1 = Server.CreateObject("Msxml2.DOMDocument.3.0")
: XmlSource = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
: "<!DOCTYPE FREIGHT SYSTEM ""test2004123001.dtd"">" &
: vbCrLf & _
: "<FREIGHT />"
: XmlDocument1.validateOnParse = False
: XmlDocument1.loadXML(XmlSource)

Thanks Martin but then how do I get that to save to a file?
If I use XmlDocument1.save(XmlFileName) the file is 0 bytes.
 
M

Martin Honnen

Roland Hall wrote:

Thanks Martin but then how do I get that to save to a file?
If I use XmlDocument1.save(XmlFileName) the file is 0 bytes.

I think before calling loadXML one needs to set
resolveExternals = False
as otherwise the XML parser would try to load the DTD but can't resolve
the relative URL. Then the following example works here for me:

<%@ Language="VBScript" %>
<%
Dim XmlDocument1, XmlSource, FileName, Element, Loaded
Set XmlDocument1 = Server.CreateObject("Msxml2.DOMDocument.3.0")
XmlSource = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
"<!DOCTYPE FREIGHT SYSTEM ""test2004123001.dtd"">" &
vbCrLf & _
"<FREIGHT />"
XmlDocument1.validateOnParse = False
XmlDocument1.resolveExternals = False
Loaded = XmlDocument1.loadXML(XmlSource)
If Loaded Then
Set Element = XmlDocument1.createElement("BOX")
Element.appendChild(XmlDocument1.createTextNode("bicycle"))
XmlDocument1.documentElement.appendChild(Element)
FileName = "test2004123002Output.xml"
XmlDocument1.save Server.MapPath(FileName)
Response.Write "<p><a href=""" & FileName & """>XML</a></p>" & vbCrLf
Else
Response.Write "<p>" & XmlDocument1.parseError.reason & "</p>"
End If
%>

The file is saved and can be loaded from the link generated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top