Bartok
(Thomas Paik)
1
How do I add a conditional statement such as IF ELSE into XML code in Extract Structured Data activity?
I am new to XML so please kindly provide a working XML code solution. Thank you.
[example pseudo code]
<extract>
<row exact='1'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
</row>
**IF <column exact='1' name='her' attr='text'> isNullorEmpty THEN**
<column exact='1' name='him' attr='alt'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
<webctrl tag='img' idx='1' />
</column>
**ELSE**
<column exact='1' name='her' attr='text'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
</column>
**END IF**
</extract>
Bartok
(Thomas Paik)
2
if attribute of ‘text’ has value null or empty then
…
else
…
end if
[REVISED example pseudo code]
<extract>
<row exact='1'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
</row>
**IF <column exact='1' name='her' attr='text'> isNullorEmpty THEN**
<column exact='1' name='her' attr='alt'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
<webctrl tag='img' idx='1' />
</column>
**ELSE**
<column exact='1' name='her' attr='text'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
</column>
**END IF**
</extract>
you dont need if-else i think
just put them on top of each other. Data scraping will see which one exists, and will use the one that exists
<column exact='1' name='her' attr='alt'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
<webctrl tag='img' idx='1' />
</column>
<column exact='1' name='her' attr='text'>
<webctrl tag='div' />
<webctrl tag='li' idx='1' />
<webctrl tag='div' idx='1' />
<webctrl tag='div' idx='3' />
<webctrl tag='div' idx='1' />
<webctrl tag='a' idx='1' />
</column>
Bartok
(Thomas Paik)
4
Thanks. It seems to work.
But I also get a new empty column named “her1”.
put this in if statement
String.IsNullOrEmpty(String.Join(",", dt.AsEnumerable.Select(function(row) row("her1").ToString).ToList))
this will check if her1 column is empty, if empty then you can delete it
ppr
(Peter)
6
would recommend to scrap the him and her column as two correlated columns and doing the evaluation afterwards on datatable level
Bartok
(Thomas Paik)
7
Yes, that was my original process indeed.
I was wondering if it could be done directly from XML code instead of evaluating the data table afterwards.
ppr
(Peter)
8
the available functionality triggered with the XML extract config does not offer an if/else condition functionality so far
Bartok
(Thomas Paik)
9
OK. Thanks for clarifying this issue.
system
(system)
Closed
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.