 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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
|
|
|
|

March 30th, 2010, 02:24 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Do not know how to loop through this xml file
I have this xml file
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 id="Uitleg4">Uitleg</action>
</action>
</wizard>
I loop through this file and generate html from it. Like this (pseudo code)
Code:
select case actionType
case "Uitleg"
Do create text formfield
case "IfElseActivity"
Do create dropdownbox
case "IfElseBranchActivity"
Do create option in dropdownbox
end select
The sequence I loop through the xml is:
Code:
uitleg2
uitleg1
IfElseActivity1
IfElseBranchActivity1
uitleg3
IfElseBranchActivity2
uitleg4
This gives me a problem. When I get the Ifelseactivity, I need to know how much branches I have. First I want to 'build' the ifelseactivity1 dropdown BEFORE I build the uitleg 3 text formfield.
keep in mind that this xml is very simple, it can become complicated when I get an IfElseActivity In an IfElseActivity and so on.
I hope I made my problem clear.
I gave it a try in ASP and XSLT but I ended up in a lot of If then Else and case contructions which became a mess...
|
|

March 30th, 2010, 03:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Why not simply do something like this:
Code:
Sub ProcessOneLevel( ... whatever the arguments? ... )
Dim textList : ReDim textList(0)
select case actionType
case "Uitleg"
ReDim Preserve textList(UBound(textList)+1)
textList(UBound(textList) = ... remember this formfield ...
case "IfElseActivity"
Do create dropdownbox
case "IfElseBranchActivity"
Do create option in dropdownbox
case "</IfElseActivity"
generate the </select>
For i = 1 To UBound(textList)
Create a text box from textList(i)
Next
end select
End Sub
???
By putting the textList in the sub and making it a local variable, you can even handle nesting, base on other tags.
If a one-dimensional array is too simplistic, make it a 2D array. Or a 1D array of instances of a VBS class.
|
|

April 1st, 2010, 05:22 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Old Pedant
Why not simply do something like this:
Code:
Sub ProcessOneLevel( ... whatever the arguments? ... )
Dim textList : ReDim textList(0)
select case actionType
case "Uitleg"
ReDim Preserve textList(UBound(textList)+1)
textList(UBound(textList) = ... remember this formfield ...
case "IfElseActivity"
Do create dropdownbox
case "IfElseBranchActivity"
Do create option in dropdownbox
case "</IfElseActivity"
generate the </select>
For i = 1 To UBound(textList)
Create a text box from textList(i)
Next
end select
End Sub
???
By putting the textList in the sub and making it a local variable, you can even handle nesting, base on other tags.
If a one-dimensional array is too simplistic, make it a 2D array. Or a 1D array of instances of a VBS class.
|
I did not think of te array approach yet, this is a good one.
However the xml does nog give me the "</IfElseActivity" back. How can I read this end tag?
|
|

April 1st, 2010, 04:18 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
> However the xml does nog give me the "</IfElseActivity" back.
WHAT??? How can it avoid it??? And still be legal XML??
Can't you show us the *real* XML??
|
|

April 2nd, 2010, 02:39 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Real xml
Quote:
Originally Posted by Old Pedant
> However the xml does nog give me the "</IfElseActivity" back.
WHAT??? How can it avoid it??? And still be legal XML??
Can't you show us the *real* XML??
|
This is the real xml:
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 id="Uitleg4">Uitleg</action>
</action>
</wizard>
I am able to change it, a bit. What should be better in order to get back the </ifelseactivity
|
|

April 2nd, 2010, 05:58 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Oh! Ugh!
Yeah, now I remember seeing this before.
You don't really have much choice but to do this in full XML node processing style.
BUT WAIT! You *must* have an error there.
Compare <action id="IfElseBranchActivity1"> with <action id="IfElseBranchActivity2">
One has the Uitleg3 *inside* its <action>...</action> pair and the other has it *outside*.
Surely that is wrong??
|
|

April 2nd, 2010, 06:03 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Is there a reason you opted to go with all <action>...</action> instead of using tags such as
Code:
<wizard wizardid="Workflow1">
<uitleg id="Uitleg2">Uitleg</uitleg>
<uitleg id="Uitleg1">Uitleg</uitleg>
<ifelse id="IfElseActivity1">
IfElseActivity
<ifelsebranch id="IfElseBranchActivity1">
IfElseBranchActivity
<uitleg id="Uitleg3">Uitleg</uitleg>
</ifelsebranch>
<ifelsebranch id="IfElseBranchActivity2">
IfElseBranchActivity
<uitleg id="Uitleg4">Uitleg</uitleg>
</ifelsebranch>
</ifelse>
</wizard>
??? That would be MUCH more in keeping with the spirit of XML and not so incidentally much easier to process.
|
|

April 3rd, 2010, 11:33 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Old Pedant
Is there a reason you opted to go with all <action>...</action> instead of using tags such as
Code:
<wizard wizardid="Workflow1">
<uitleg id="Uitleg2">Uitleg</uitleg>
<uitleg id="Uitleg1">Uitleg</uitleg>
<ifelse id="IfElseActivity1">
IfElseActivity
<ifelsebranch id="IfElseBranchActivity1">
IfElseBranchActivity
<uitleg id="Uitleg3">Uitleg</uitleg>
</ifelsebranch>
<ifelsebranch id="IfElseBranchActivity2">
IfElseBranchActivity
<uitleg id="Uitleg4">Uitleg</uitleg>
</ifelsebranch>
</ifelse>
</wizard>
??? That would be MUCH more in keeping with the spirit of XML and not so incidentally much easier to process.
|
Ok, I try to change it that way. How can I process this?
|
|

April 6th, 2010, 01:14 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Well, if you change to this kind of format, then what I showed you *should* work.
The only reason it might not work as is would be if you have on <ifelse> *inside* anothe <ifelse>. But even that we could make work, with a little bit of care.
|
|

April 6th, 2010, 03:26 PM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Old Pedant
Well, if you change to this kind of format, then what I showed you *should* work.
The only reason it might not work as is would be if you have on <ifelse> *inside* anothe <ifelse>. But even that we could make work, with a little bit of care.
|
Ok, I tried this:
Code:
Set xml = CreateObject("msxml2.DomDocument")
xml.async = false
xml.load (Server.MapPath("test2.xml"))
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
Which gives me the following output:
Code:
(2) /wizard[id=Workflow1]/uitleg[id=Uitleg2] = Uitleg
(2) /wizard[id=Workflow1]/uitleg[id=Uitleg1] = Uitleg
(2) /wizard[id=Workflow1]/ifelse[id=IfElseActivity1] = IfElseActivity
(3) /wizard[id=Workflow1]/ifelse[id=IfElseActivity1]/ifelsebranch[id=IfElseBranchActivity1] = IfElseBranchActivity
(4) /wizard[id=Workflow1]/ifelse[id=IfElseActivity1]/ifelsebranch[id=IfElseBranchActivity1]/uitleg[id=Uitleg3] = Uitleg
(3) /wizard[id=Workflow1]/ifelse[id=IfElseActivity1]/ifelsebranch[id=IfElseBranchActivity2] = IfElseBranchActivity
(4) /wizard[id=Workflow1]/ifelse[id=IfElseActivity1]/ifelsebranch[id=IfElseBranchActivity2]/uitleg[id=Uitleg4] = Uitleg
This already is very nice but does not give me the endtag </ifelse or </ifelsebranch. How can I achieve that.
And thank again for all your help sofar, really appreciate that!!!
|
|
 |