devildogv23
IS-IT--Management
I am trying to extend a simple example and can't get it to place the node in the correct place, nor can I get the delete node to work. Any help would be appreciated..
sample that works:
<customers>
<customer CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" />
<customer CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" />
<customer CustomerID="ANTON" CompanyName="Antonio Moreno Taqueria" />
</customers>
As soon as this sample is down another layer, I can't get the same results.
Sample XML file that doesn't work:
<XMI>
<customers>
<customer CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" />
<customer CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" />
<customer CustomerID="ANTON" CompanyName="Antonio Moreno Taqueria" />
</customers>
</XMI>
Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="Customers.css" >
</head>
<body>
<center>
<div class="pagetitle ">Original XML Values</div><br>
<textarea cols=110 id=txtOrig name=txtOrig rows=10></textarea>
<br><br>
<div class="pagetitle ">New XML Values</div><br>
<textarea cols=111 id="txtNew" name=txtNew rows=11></textarea>
</center>
<input type="button" value="Delete" onclick="doDelete()" id="btnDelete" name="btnDelete"></input>
<input type="button" value="Update" onclick="doUpdate()" ID="btnUpdate" NAME="btnUpdate"></input>
<input type="button" value="Insert" onclick="doInsert()" ID="Button1" NAME" NAME="btnInsert"></input>
</body>
</html>
<script language="VBscript">
function doDelete()
dim objNode, objDOM, strXPath
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
' Create an instance of the node that you with do delete
' XPath is used to specify the location of the node. This demo interprets to
' selecting the node where the customerID attribute = "ANTON"
strXPath = "XMI/customers/customer[@CustomerID='ANTON']"
set objNode = objDOM.selectSingleNode(strXPath)
'Now, remove the selected node from the XML DOM object
objDOM.documentElement.removeChild(objNode)
'Display the new contents
txtNew.value = objDOM.xml
end function
function doUpdate()
dim objNode, objDOM, strXPath
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
'Below are some examples of how to update the contents of an XML Element
' Create an instance of the node that you with do delete
' XPath is used to specify the location of the node. This demo interprets to
' selecting the node where the customerID attribute = "ANTON"
strXPath = "XMI/customers/customer[@CustomerID='ANTON']/@CompanyName"
objDOM.selectSingleNode(strXPath).text = "new value 1"
objDOM.selectSingleNode( "XMI/customers/customer[@CustomerID='ANATR']/@CompanyName").text = "new value 2"
objDOM.selectSingleNode( "XMI/customers/customer[0]/@CompanyName").text = "new value 3"
'Display the new contents
txtNew.value = objDOM.xml
end function
function doInsert()
dim objNode, objDOM
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
Set objRoot = objDom.documentElement.selectSingleNode("XMI/customers")
'Create a new Node object
Set objNode = objRoot.createNode(1,"customer","")
'Add the objects to the newly created Node
AddNodeAttribute objDOM, objNode, "CustomerID", "XMLP"
AddNodeAttribute objDOM, objNode, "CompanyName", "XMLPitstop.com"
'Display the new contents
txtNew.value = objDOM.xml
end function
Sub AddDomElement(objDom, strName, strValue)
Dim objNode
'Add new node
Set objNode = objDom.createElement(strName)
objNode.Text = strValue
objDom.documentElement.appendChild objNode
End Sub
Sub AddNodeAttribute(objDom, objNode, strName, strValue)
Dim objAttrib
Set objAttrib = objDOM.createAttribute(strName)
objAttrib.Text =strValue
objNode.Attributes.setNamedItem objAttrib
objDOM.documentElement.appendChild objNode
End Sub
</script>
sample that works:
<customers>
<customer CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" />
<customer CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" />
<customer CustomerID="ANTON" CompanyName="Antonio Moreno Taqueria" />
</customers>
As soon as this sample is down another layer, I can't get the same results.
Sample XML file that doesn't work:
<XMI>
<customers>
<customer CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" />
<customer CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" />
<customer CustomerID="ANTON" CompanyName="Antonio Moreno Taqueria" />
</customers>
</XMI>
Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="Customers.css" >
</head>
<body>
<center>
<div class="pagetitle ">Original XML Values</div><br>
<textarea cols=110 id=txtOrig name=txtOrig rows=10></textarea>
<br><br>
<div class="pagetitle ">New XML Values</div><br>
<textarea cols=111 id="txtNew" name=txtNew rows=11></textarea>
</center>
<input type="button" value="Delete" onclick="doDelete()" id="btnDelete" name="btnDelete"></input>
<input type="button" value="Update" onclick="doUpdate()" ID="btnUpdate" NAME="btnUpdate"></input>
<input type="button" value="Insert" onclick="doInsert()" ID="Button1" NAME" NAME="btnInsert"></input>
</body>
</html>
<script language="VBscript">
function doDelete()
dim objNode, objDOM, strXPath
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
' Create an instance of the node that you with do delete
' XPath is used to specify the location of the node. This demo interprets to
' selecting the node where the customerID attribute = "ANTON"
strXPath = "XMI/customers/customer[@CustomerID='ANTON']"
set objNode = objDOM.selectSingleNode(strXPath)
'Now, remove the selected node from the XML DOM object
objDOM.documentElement.removeChild(objNode)
'Display the new contents
txtNew.value = objDOM.xml
end function
function doUpdate()
dim objNode, objDOM, strXPath
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
'Below are some examples of how to update the contents of an XML Element
' Create an instance of the node that you with do delete
' XPath is used to specify the location of the node. This demo interprets to
' selecting the node where the customerID attribute = "ANTON"
strXPath = "XMI/customers/customer[@CustomerID='ANTON']/@CompanyName"
objDOM.selectSingleNode(strXPath).text = "new value 1"
objDOM.selectSingleNode( "XMI/customers/customer[@CustomerID='ANATR']/@CompanyName").text = "new value 2"
objDOM.selectSingleNode( "XMI/customers/customer[0]/@CompanyName").text = "new value 3"
'Display the new contents
txtNew.value = objDOM.xml
end function
function doInsert()
dim objNode, objDOM
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XMLDOM")
objDOM.async = false
objDOM.load("Customers.xml")
'Display the original XML values
txtOrig.value = objDOM.xml
Set objRoot = objDom.documentElement.selectSingleNode("XMI/customers")
'Create a new Node object
Set objNode = objRoot.createNode(1,"customer","")
'Add the objects to the newly created Node
AddNodeAttribute objDOM, objNode, "CustomerID", "XMLP"
AddNodeAttribute objDOM, objNode, "CompanyName", "XMLPitstop.com"
'Display the new contents
txtNew.value = objDOM.xml
end function
Sub AddDomElement(objDom, strName, strValue)
Dim objNode
'Add new node
Set objNode = objDom.createElement(strName)
objNode.Text = strValue
objDom.documentElement.appendChild objNode
End Sub
Sub AddNodeAttribute(objDom, objNode, strName, strValue)
Dim objAttrib
Set objAttrib = objDOM.createAttribute(strName)
objAttrib.Text =strValue
objNode.Attributes.setNamedItem objAttrib
objDOM.documentElement.appendChild objNode
End Sub
</script>