DotDragnet
February 08, 2012, 10:51:03 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Help decide how we fund DDN and where we take the community from here. Post in the thread all about it: http://www.dotdragnet.com/forum/index.php/topic,4368.0.html
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Classic ASP and XML  (Read 1272 times)
hacking_mike
Guest
« on: January 31, 2010, 12:09:41 PM »

I get this piece of XML from an application

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<wizard wizardid="Workflow1">
<action id="Uitleg2">Uitleg</action>
<action id="Uitleg1">Uitleg</action>
<action id="IfElseActivity1">IfElseActivity

  <action id="IfElseBranchActivity1">IfElseBranchActivity
     <action id="Uitleg3">Uitleg</action>
  </action>

   <action id="IfElseBranchActivity2">IfElseBranchActivity</action>

</action>
</wizard>

I try to create an ASP function which reads the XML and gives me back the 'id' and the text (for example 'ifelsebranchactivity1' and 'ifelsebranchactivity'). As you can see "IfElseActivity1" has childs and one child has a subchild. This can go very deep in this xml. So a need a nice 'loop' function which checks if there is a child and so on.

Now I have this but I can't figure out how to get a nice clean function
Code:
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load (Server.MapPath("test.xml"))
Dim objChildNodes, strNode
Set objChildNodes = xml.documentElement.childNodes
For Each strNode In objChildNodes 
        response.write(strNode.nodename & " " & strNode.getAttribute("id") & "<br>")
        If strNode.hasChildNodes() then
          response.write(strNode.getAttribute("id") & " " & "has child nodes" & "<br>")
           set oNodeList2 = strNode.childnodes
           For Each node2 In oNodeList2
            response.write(node2.nodevalue & "<br>")
             If node2.hasChildNodes() then
              response.write(node2.getAttribute("id") & "has child nodes" & "<br>")
              end if
          Next
       end if       
Next
Set xml = Nothing

Can someone put me in the right direction?
Logged
Jeep Stone
Hero Member
*****
Posts: 906



View Profile WWW Awards
« Reply #1 on: February 01, 2010, 09:49:15 AM »

You could do this with XSLT instead maybe? Run the XML through an XSLT transform and get the value back out?
Logged

hacking_mike
Guest
« Reply #2 on: February 01, 2010, 02:15:39 PM »

Hmmm, that's a bit complicated (for me). Isn't there an easy way to do this? In Javascript I have it working but I need tot have the data in ASP to do some more programming. I can't pass the client side javascript to server side ASP..
« Last Edit: February 01, 2010, 03:45:16 PM by hacking_mike » Logged
Jeep Stone
Hero Member
*****
Posts: 906



View Profile WWW Awards
« Reply #3 on: February 01, 2010, 06:01:42 PM »

It's been too long for me on the classic ASP. I'd take a look at http://www.4guysfromrolla.com/webtech/101600-1.shtml as they had some good resources when I was doing it.

The process would be something like:

Open XML
Open XSLT
Transform XML
Grab value back out in ASP.

Of course, I'd imagine that you should be able to get the value using just ASP but it's been too long.
Logged

hacking_mike
Guest
« Reply #4 on: February 02, 2010, 08:36:49 AM »

I will try that. Thanks!
Meanwhile I tried to create an ASP function and came on with this:
Code:
dim objChildNodes, strNode
dim xml

function loadXML()
Response.Buffer = True
  Set xml =  server.createobject(“Microsoft.xmldom”)
xml.async = false
xml.load (Server.MapPath("test.xml"))
  openXml()
end function

function openXml()
set objchildnodes = xml.documentelement.childnodes
For Each strNode In objChildNodes
Readnode(strNode)
Next
End function

Function readNode()
response.write(strNode.nodename & " " & strNode.getAttribute("id") & "<br>")

If strNode.hasChildNodes() then
Readnode(strNode)
End if
End function


i can't test it at this moment (don't have IIs over here. must do that tonight). Does anyone thinks that this might work?
Logged
hacking_mike
Guest
« Reply #5 on: February 03, 2010, 12:27:06 PM »

Code:
dim xml

Response.Buffer = True
Set xml =  server.createobject("Microsoft.xmldom")
xml.async = false
xml.load (Server.MapPath("test.xml"))
openXml()


function openXml()
dim objChildNodes, strNode
set objNode = XML.selectNodes("wizard/action")
    For i = 0 To (objNode.length - 1)
        Set objChildNodes = objNode(i)
Readnode(objChildNodes)
Next
End function

Function readNode(strNode2)
on error resume next
response.write(strNode2.nodename & " " & strNode2.text & " " & strNode2.getAttribute("id") & "<br>")
on error goto 0

If strNode2.hasChildNodes() then
        set oNodeList2 = strNode2.childnodes
For Each node2 In oNodeList2
Readnode(node2)
Next
End if
End function
This is the result

Code:
action Uitleg Uitleg2
action Uitleg Uitleg1
action IfElseActivity IfElseBranchActivity Uitleg IfElseBranchActivity IfElseActivity1
action IfElseBranchActivity Uitleg IfElseBranchActivity1
action Uitleg Uitleg3
action IfElseBranchActivity IfElseBranchActivity2

When there are children and grandchildren the result is a bit odd. strNode2.text gives me all the textnode of a parentnode. Is there a way to change this?
Logged
hacking_mike
Guest
« Reply #6 on: February 04, 2010, 09:11:11 PM »

Can someone help me out?
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!