 |
| Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 2nd, 2010, 03:32 PM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Loop through xml
Im a bit stuck. Tried different things without result.
This is the xml i get 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 want to loop trough this xml to read id and action (for example 'uitleg2' and 'uitleg') The xml can go a lot of levels deep. So I need a function to loop through the xml. This is what I have but, of course, does not work.
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
This result is a bit funny...
Can someone help me out?
Last edited by hacking_mike; February 2nd, 2010 at 04:20 PM..
|
|

February 2nd, 2010, 10:04 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Helps to format the XML readably...
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>
Okay, that's sensible.
So what *DO* you want the OUTPUT to be???
*IF* you intend to IGNORE the id values, then I would think that a reasonable result might be
Code:
Uitleg
Uitleg
IfElseActivity > IfElseBranchActivity > Uitleg
IfElseActivity > IfElseBranchActivity
But maybe that's not what you intended??
|
|

February 3rd, 2010, 02:43 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Code:
I do want to have the id values back so:
uitleg2 > uitleg
uitleg1 > uitleg
Ifelseactivity1 > ifelseactivity
ifelsebranchactivity1 > ifelsebranchactivity
uitleg3 > uitleg
ifelsebranchactivity2 > ifelsebranchactivity
The i need to know the 'depth' of the children (is there a property for that?). I need to know that uitleg3 is a child of ifelsebranchactivity1 which is a child of ifelsebranchactivity
I hope this clears things up
|
|

February 3rd, 2010, 05:32 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I want the output to be:
Code:
Uitleg Uitleg2
Uitleg Uitleg1
IfElseActivity IfElseActivity1
IfElseBranchActivity IfElseBranchActivity1
Uitleg Uitleg3
IfElseBranchActivity IfElseBranchActivity2
I also need to now the level of the children so that I know that IfElseBranchActivity1
and IfElseBranchActivity2 are children of IfElseActivity1 and Uitleg3 is a child of IfElseBranchActivity1.
|
|

February 3rd, 2010, 03:08 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
But how do you want the data presented???
We could do this easily enough:
Code:
Uitleg2::Uitleg
Uitleg1::Uitleg
IfElseActivity1::IfElseActivity > IfElseBranchActivity1::IfElseBranchActivity > Uitleg3::Uitleg
IfElseActivity1::IfElseActivity > IfElseBranchActivity2::IfElseBranchActivity
Where I'm using :: to indicate id/text value pairs and > to indicate levels.
Change the delimiters to suit yourself.
Or we could do this:
Code:
(1)Uitleg2>Uitleg
(1)Uitleg1>Uitleg
(1)IfElseActivity1>IfElseActivity
(2)IfElseBranchActivity1>IfElseBranchActivity
(3)Uitleg3>Uitleg
(2)IfElseBranchActivity2>IfElseBranchActivity
That tells depth but doesn't say who is a child of whom.
Again, how should the full data be presented???
[/code]
|
|

February 4th, 2010, 05:47 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I think this will do it
Quote:
Originally Posted by Old Pedant
But how do you want the data presented???
Code:
(1)Uitleg2>Uitleg
(1)Uitleg1>Uitleg
(1)IfElseActivity1>IfElseActivity
(2)IfElseBranchActivity1>IfElseBranchActivity
(3)Uitleg3>Uitleg
(2)IfElseBranchActivity2>IfElseBranchActivity
|
In the loop I want to create a dynamic form. With a case statement. So 'uitleg' means a textbox. With the value 'Uitleg2' I read in the database to have the initial value of the textbox.
'IfElseActivity' will be a dropdown. the IfElseBranchActivity's is the number of options in the dropdown and so on. So your example is ok. How do I achive this?
|
|

February 4th, 2010, 04:24 PM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Please
Can someone help me out please. Tried for another day but still did not find the solution.
|
|

February 4th, 2010, 09:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
It would have helped *A LOT* if you had simply SHOWN the <form> you want to produce from that HTML.
See, what you say *still* doesn't make sense.
Quote:
|
So 'uitleg' means a textbox. With the value 'Uitleg2'
|
FIne. Now what is the *NAME* of the textbox???
Is it supposed to be
Code:
<input name="uitleg" value="Uitleg2" />
or did you miswrite that??? Did you mean "name" when you wrote "value"?? That is:
Code:
<input name="Uitleg2"/>
???
PLEASE show the ACTUAL <form> that you want to have result from that XML.
This one, especially, makes no sense:
Code:
IfElseActivity1::IfElseActivity > IfElseBranchActivity1::IfElseBranchActivity > Uitleg3::Uitleg
??? You want a textbox *inside* a <select>??? I dont' get that.
|
|

February 5th, 2010, 03:25 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Try to explain
Quote:
Originally Posted by Old Pedant
It would have helped *A LOT* if you had simply SHOWN the <form> you want to produce from that HTML.
See, what you say *still* doesn't make sense.
FIne. Now what is the *NAME* of the textbox???
Is it supposed to be
Code:
<input name="uitleg" value="Uitleg2" />
or did you miswrite that??? Did you mean "name" when you
|
The name for the textbox I will read from the database but the result will be something like this.
Code:
<input name="fromDatabase" value="Uitleg2" />
It is very complicated and I can't show you much as I'm still prototyping.
Can't you explain me how I can read the depth en how the text property only gives me the first "word".
Sorry that I can't make it very clear.
I read the xml > this gives me "uitleg2" > with the information from the database and the xml file I contruct a formfield.
Bottemline is: How do I get the information from the xml?
|
|

February 5th, 2010, 07:07 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I'm still not sure exactly what to give you, but here:
Code:
<%
testxml = _
"<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbNewLine & _
"<wizard wizardid=""Workflow1"">" & vbNewLine & _
"<action id=""Uitleg2"">Uitleg</action>" & vbNewLine & _
"<action id=""Uitleg1"">Uitleg</action>" & vbNewLine & _
"<action id=""IfElseActivity1"">" & vbNewLine & _
" IfElseActivity" & vbNewLine & _
" <action id=""IfElseBranchActivity1"">" & vbNewLine & _
" IfElseBranchActivity" & vbNewLine & _
" <action id=""Uitleg3"">Uitleg</action>" & vbNewLine & _
" </action>" & vbNewLine & _
" <action id=""IfElseBranchActivity2"">IfElseBranchActivity</action>" & vbNewLine & _
"</action>" & vbNewLine & _
"</wizard>"
Set xml = CreateObject("msxml2.DomDocument")
xml.LoadXML testxml
Set start = xml.SelectSingleNode("wizard")
Recurse start, "", 0
Sub Recurse( node, path, level )
Dim kids, kid, nname, nid
If node.nodeTypeString = "text" Then
Response.Write "(" & level & ") " & path & " = " & node.Text & "<br/>" & vbNewLine
Else
nname = node.nodeName
nid = node.Attributes(0).value
Set kids = node.ChildNodes
For Each kid In kids
Recurse kid, path & "/" & node.nodeName & "[id=" & nid & "]", level+1
Next
End If
End Sub
%>
That code produces this output:
Code:
(2) /wizard[id=Workflow1]/action[id=Uitleg2] = Uitleg
(2) /wizard[id=Workflow1]/action[id=Uitleg1] = Uitleg
(2) /wizard[id=Workflow1]/action[id=IfElseActivity1] = IfElseActivity
(3) /wizard[id=Workflow1]/action[id=IfElseActivity1]/action[id=IfElseBranchActivity1] = IfElseBranchActivity
(4) /wizard[id=Workflow1]/action[id=IfElseActivity1]/action[id=IfElseBranchActivity1]/action[id=Uitleg3] = Uitleg
(3) /wizard[id=Workflow1]/action[id=IfElseActivity1]/action[id=IfElseBranchActivity2] = IfElseBranchActivity
The number at the front is the "depth" (level number) where the match was found.
The "path" then shows:
/nodeTagName[id=nodeId]
and, at the end, the text of the node, when found.
You should be able to remove the parts of that which you don't care about to get what you need.
|
|
 |