A Couple of ASP Functions for XML Data Transfer

A Couple of ASP Functions for XML Data Transfer

Introduction

One of our visitors decided they would give something back. It’s not much, but here are a couple of ASP functions for XML Data transfer that they found to be very useful.

Two functions that allow for XML Data transfer

getXMLField

Function getXMLField(strFieldName)

    Dim objDom
    Dim objRoot
    Dim objField
    Dim strFile
    Dim PageNo

    PageNo = Request.QueryString("page")
    If PageNo = "" Then
        PageNo = "1"
    End If

    'Page Number
    strFile = "Page" & PageNo & ".xml"

    'XML file object
    Set objDom = Server.CreateObject("Microsoft.XMLDOM")
    objDom.async = False
    strXMLFile = Server.MapPath(strFile)
    objDom.Load (strXMLFile)

    'Root XML Field
    Set objRoot = objDom.documentElement

    'collect information from nodes
    Set objField = objRoot.selectSingleNode(strFieldName)

    getXMLField = objField.Text

    'Release variables
    Set objDom = Nothing
    Set objRoot = Nothing
    Set objField = Nothing

End Function

updateXMLField

Function updateXMLField(strFieldName, strData2BInserted, strXMLFile)

    Dim objDom
    Dim objRoot
    Dim objField

    'XML file object
    Set objDom = Server.CreateObject("Microsoft.XMLDOM")
    objDom.async = False
    objDom.Load strXMLFile

    'Root XML Field
    Set objRoot = objDom.documentElement

    'Select single XML node given the node name
    Set objField = objRoot.selectSingleNode(strFieldName)

    'update field
    objField.Text = strData2BInserted

    objDom.save strXMLFile
    updateXMLField = True

    'Release all objects
    Set objDom = Nothing
    Set objRoot = Nothing
    Set objField = Nothing

End Function

Thanks to [email protected] for the above code!

If you’ve got an article or a code snippet that you’d to share, drop us an email.

Related posts

SOAP Soup

Introduction Simple Object Access Protocol is one of the neatest XML based technologies to be introduced as of late, yet many people are still trying to get a handle on all of the new terms and acronyms that SOAP has uncovered. This article is written to help you dig through the SOAP...

Read More

Using XML to build an ASP+ config.web Editor

Introduction ASP+ configuration information is stored in XML-based configuration files. Using built-in features of IIS 5.0 and IE 5.0 such as the FileSystemObject, the XML Document Object Model (DOM) and XML Data Islands, we can easily develop a rich tool for modifying and editing these configuration files. In this...

Read More

Saving HTML Form Data to XML

Introduction This example assumes that you are familiar with ASP, XML and HTML 4.0. Storing your form submissions in XML Usually form submissions in ASP are written to some sort of database management system. However, if you need your form submission data to be more portable, it can be...

Read More