Create using VBScript

Keywords: XML, create, VBScript, DOMDocument, TextNode, root, MSXML2, .xml
1.
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
Set rootElement = xmlDoc.createElement("memo")
Set memoAttribute = xmlDoc.createAttribute("author")
Set memoAttributeText = xmlDoc.createTextNode("Pat Coleman")
memoAttribute.appendChild(memoAttributeText)
rootElement.setAttributeNode(memoAttribute)
xmlDoc.appendChild(rootElement)

xmlDoc.save ("c:\MyStuff\xml\memo.xml")

2.
Set xmlDoc = CreateObject("MSXML2.DOMDocument.4.0")
xmlDoc.load("<customer><first_name>Joe</first_name><last_name>Smith</last_name></customer>")
alert(xmlDoc)

xmlDoc.save ("c:\MyStuff\xml\customer.xml")

DOM

Keywords: XML, DOM, XMLDOM, MapPath, MSXML2, XMLHTTP, transformNode
<%
'Load the XML
Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
xmlObj.async = False
xmlObj.load(Server.MapPath("address_book.xml"))

'Load the XSL
Set xslObj = Server.CreateObject("Microsoft.XMLDOM")
xslObj.async = False
xslObj.load(Server.MapPath("address_book.xsl"))

Response.Write(xmlObj.transformNode(xslObj))
%>

<%
' Get Remote XML 
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") 
objXMLHTTP.open "GET","http://www.charlesjanco.com/test/address_book.xml", false 
objXMLHTTP.send 


'Load the XML 
Set xmlObj = Server.CreateObject("MSXML2.DOMDocument") 
xmlObj.async = False 
xmlObj.loadXML objXMLHTTP.ResponseXML.xml 


'Load the XSL 
Set xslObj = Server.CreateObject("MSXML2.DOMDocument") 
xslObj.async = False 
xslObj.load Server.MapPath("address_book.xsl") 


Response.Write xmlObj.transformNode(xslObj)
%>

Recordset

Keywords: XML, recordset, XMLDOM, getAttribute
<%
Function RS_XML(f_sXML, ByRef v_oRS)
	Set f_oDOM = Server.CreateObject("Microsoft.XMLDOM")
	f_oDOM.async = False
	f_oDOM.loadXML(f_sXML)
	
	Set f_oRS = f_oDOM.getElementsByTagName("rs:data/z:row")

	' Error
	If err.number <> 0 Then
		Set f_oDOM = Nothing
		Set f_oRS = Nothing
		RS_XML = False
		Exit Function
	End If

	' Success
	Set v_oRS = f_oRS
	RS_XML = (Err.number = 0)
	Set f_oDOM = Nothing
	Set f_oRS = Nothing
	Exit Function
End Function

v_iNumberRecords = v_oRS.length - 1

For i = 0 To v_iNumberRecords
	v_sHeadline = v_oRS.item(i).getAttribute("Headline")
	v_iID = v_oRS.item(i).getAttribute("ContentID")
Next

Set v_oRS = Nothing
%>

XML File

Keywords: XML, file
<?xml version="1.0" encoding="ISO8859-1"?>
<?xml-stylesheet type="text/xsl" href="address_book.xsl"?>
<address_book>
  <contact ID="100">
    <name>Fred Flintstone</name>
    <city>Bedrock</city>
    <email>fred@flintstone.com</email>
    <phone>800-555-1212</phone>
  </contact>
  <contact ID="101">
    <name>Barney Rubble</name>
    <city>Bedrock</city>
    <email>barney@flintstone.com</email>
    <phone>800-555-1212</phone>
  </contact> 
</address_book>

XSL

Keywords: XML, XSL, template, for-each, choose, otherwise
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>Address Book</title>
</head>
<body bgcolor="#ffffff">
<table align="center" border="0" cellpadding="4" cellspacing="0" width="60%">
<tr bgcolor="#cccccc">
  <th>Name</th>
  <th>City</th>
  <th>E-Mail</th>
</tr>
<xsl:for-each select="address_book/contact" order-by="+ name">
  <xsl:choose>
   <xsl:when expr="childNumber(this) > 2"></xsl:when>
   <xsl:otherwise>
    <tr>
     <td>
      <xsl:value-of select="name"/>
     </td>
     <td>
      <xsl:value-of select="city"/>
     </td>
     <td>
      <xsl:value-of select="email"/>
     </td>
    </tr>
    <tr bgcolor="#cccccc"><td colspan="3"></td></tr>
   </xsl:otherwise>
  </xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>