Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > doctype

Reply
Thread Tools

doctype

 
 
Roland Hall
Guest
Posts: n/a
 
      12-30-2004
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


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-30-2004


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)

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Roland Hall
Guest
Posts: n/a
 
      12-30-2004

"Martin Honnen" <> wrote in message
news:...
:
:
: 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.


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-31-2004


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("b icycle"))
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Newbie - CSS Works With Invalid DOCTYPE. Fails With Valid DOCTYPE. Larry Lindstrom HTML 19 06-12-2012 02:07 PM
Changing DOCTYPE in template Jake ASP .Net 0 08-17-2005 12:50 PM
DOCTYPE declarations not generated by ASP.NET Neil Zanella ASP .Net 3 01-04-2005 11:18 PM
Setting DocType in Asp.Net Kenneth Keeley ASP .Net 1 06-30-2004 01:59 PM
vs.net creates doctype wrong? Ian ASP .Net 2 06-21-2004 12:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57