doctype

Discussion in 'ASP General' started by Roland Hall, Dec 30, 2004.

  1. Roland Hall

    Roland Hall Guest

    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
    Roland Hall, Dec 30, 2004
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Dec 30, 2004
    #2
    1. Advertising

  3. Roland Hall

    Roland Hall Guest

    "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.
    Roland Hall, Dec 30, 2004
    #3
  4. 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 31, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian

    vs.net creates doctype wrong?

    Ian, Jun 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    474
  2. Kenneth Keeley

    Setting DocType in Asp.Net

    Kenneth Keeley, Jun 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    613
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jun 30, 2004
  3. Neil Zanella
    Replies:
    3
    Views:
    2,574
    John Saunders
    Jan 4, 2005
  4. Jake

    Changing DOCTYPE in template

    Jake, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    394
  5. Larry Lindstrom
    Replies:
    19
    Views:
    1,288
    Jonathan N. Little
    Jun 12, 2012
Loading...

Share This Page