XML Get Node

Discuss RoboTask here
Post Reply
gremlin
Posts: 50
Joined: Sun Jan 08, 2023 3:13 pm

XML Get Node

Post by gremlin »

I have a problem with XML Get Node.
These nodes are not read:

Code: Select all

                    <ADDRESS>
                        <bmecat:NAME2>Jacqueline - Test</bmecat:NAME2>
                        <bmecat:NAME3>Kales - Test</bmecat:NAME3>
                        <bmecat:STREET>Teststraße 9-13</bmecat:STREET>
                        <bmecat:ZIP>10179</bmecat:ZIP>
                        <bmecat:CITY>Berlin</bmecat:CITY>
                        <bmecat:COUNTRY>Deutschland</bmecat:COUNTRY>
                        <bmecat:COUNTRY_CODED>DE</bmecat:COUNTRY_CODED>
                        <bmecat:PHONE>089 - 24 24 11 55</bmecat:PHONE>
                        <bmecat:EMAIL>mail+m-f-ks37huh@mhhh.de</bmecat:EMAIL>
                    </ADDRESS>
it must be because of the
bmecat:NAME2
...
All other nodes without 'bmecat:' are processed successfully.
Do you have a solution for this?
Oleg
Site Admin
Posts: 3132
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: XML Get Node

Post by Oleg »

Your XML text contains some namespace - bmecat
You must declare it. The action uses system engine to process XML and get an error without declaration
You can retrieve all node values in the loop. Look at my example below

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task12"
Hide=INTEGER|0
ID=INTEGER|-2104715254
LogOnAsUser=INTEGER|1
Name=STRING|"get nodes"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""xml"" with value ""<ADDRESS>"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"xml"
expand=STRING|"0"
linecount=STRING|"11"
varname=STRING|"xml"
varvalue=STRING|"<ADDRESS>"
varvalue00000001=STRING|"                        <bmecat:NAME2>Jacqueline - Test</bmecat:NAME2>"
varvalue00000002=STRING|"                        <bmecat:NAME3>Kales - Test</bmecat:NAME3>"
varvalue00000003=STRING|"                        <bmecat:STREET>TeststraГџe 9-13</bmecat:STREET>"
varvalue00000004=STRING|"                        <bmecat:ZIP>10179</bmecat:ZIP>"
varvalue00000005=STRING|"                        <bmecat:CITY>Berlin</bmecat:CITY>"
varvalue00000006=STRING|"                        <bmecat:COUNTRY>Deutschland</bmecat:COUNTRY>"
varvalue00000007=STRING|"                        <bmecat:COUNTRY_CODED>DE</bmecat:COUNTRY_CODED>"
varvalue00000008=STRING|"                        <bmecat:PHONE>089 - 24 24 11 55</bmecat:PHONE>"
varvalue00000009=STRING|"                        <bmecat:EMAIL>mail+m-f-ks37huh@mhhh.de</bmecat:EMAIL>"
varvalue0000000A=STRING|"                    </ADDRESS>"

[Actions\Action2]
ActionID=STRING|"A_XML_LOOP"
Enabled=INTEGER|-1
Name=STRING|"XML Loop"
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"nodeName,NodeText"
ascending=STRING|"0"
attcount=STRING|"0"
loadfile=STRING|"0"
nodenamevar=STRING|"nodeName"
path=STRING|"*"
savechildcount=STRING|"0"
savedepth=STRING|"0"
savenodename=STRING|"1"
savepath=STRING|"0"
savetext=STRING|"1"
savexml=STRING|"0"
sortmode=STRING|"0"
textvar=STRING|"NodeText"
withsubnodes=STRING|"1"
xml00000000=STRING|"<root xmlns:bmecat=""http://localhost"">"
xml00000001=STRING|"{xml}"
xml00000002=STRING|"</root>"
xmlcount=STRING|"3"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"{nodeName} - {NodeText}"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Oleg Yershov
Oleg
Site Admin
Posts: 3132
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: XML Get Node

Post by Oleg »

Another way:
You can remove the namespace from this part of XML to process all necessary nodes
Look at the second example:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task19"
Hide=INTEGER|0
ID=INTEGER|2055521320
LogOnAsUser=INTEGER|1
Name=STRING|"get nodes - 2"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""xml"" with value ""<ADDRESS>"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"xml"
expand=STRING|"0"
linecount=STRING|"11"
varname=STRING|"xml"
varvalue=STRING|"<ADDRESS>"
varvalue00000001=STRING|"                        <bmecat:NAME2>Jacqueline - Test</bmecat:NAME2>"
varvalue00000002=STRING|"                        <bmecat:NAME3>Kales - Test</bmecat:NAME3>"
varvalue00000003=STRING|"                        <bmecat:STREET>TeststraГџe 9-13</bmecat:STREET>"
varvalue00000004=STRING|"                        <bmecat:ZIP>10179</bmecat:ZIP>"
varvalue00000005=STRING|"                        <bmecat:CITY>Berlin</bmecat:CITY>"
varvalue00000006=STRING|"                        <bmecat:COUNTRY>Deutschland</bmecat:COUNTRY>"
varvalue00000007=STRING|"                        <bmecat:COUNTRY_CODED>DE</bmecat:COUNTRY_CODED>"
varvalue00000008=STRING|"                        <bmecat:PHONE>089 - 24 24 11 55</bmecat:PHONE>"
varvalue00000009=STRING|"                        <bmecat:EMAIL>mail+m-f-ks37huh@mhhh.de</bmecat:EMAIL>"
varvalue0000000A=STRING|"                    </ADDRESS>"

[Actions\Action2]
ActionID=STRING|"A_STR_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"STR Replace"
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"xml"
case=STRING|"0"
mode=STRING|"0"
source=STRING|"{xml}"
substring=STRING|"bmecat:"
variable=STRING|"xml"

[Actions\Action3]
ActionID=STRING|"A_XML_GETNODE"
Enabled=INTEGER|-1
Name=STRING|"XML Get Single Node"
Params=FOLDER

[Actions\Action3\Params]
_rt_variables_produced=STRING|"NodeText"
attcount=STRING|"0"
foundresult=STRING|"1"
loadfile=STRING|"0"
ordernum=STRING|"0"
path=STRING|"*\NAME2"
raiseerror=STRING|"1"
savechildcount=STRING|"0"
savedepth=STRING|"0"
savenodename=STRING|"0"
savepath=STRING|"0"
savetext=STRING|"1"
savexml=STRING|"0"
textvar=STRING|"NodeText"
xml00000000=STRING|"{xml}"
xmlcount=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action4\Params]
message=STRING|"{NodeText}"
type=STRING|"3"

[Actions\Action5]
ActionID=STRING|"A_XML_LOOP"
Enabled=INTEGER|-1
Name=STRING|"XML Loop"
Params=FOLDER

[Actions\Action5\Params]
_rt_variables_produced=STRING|"nodeName,NodeText"
ascending=STRING|"0"
attcount=STRING|"0"
loadfile=STRING|"0"
nodenamevar=STRING|"nodeName"
path=STRING|"\ADDRESS\*"
savechildcount=STRING|"0"
savedepth=STRING|"0"
savenodename=STRING|"1"
savepath=STRING|"0"
savetext=STRING|"1"
savexml=STRING|"0"
sortmode=STRING|"0"
textvar=STRING|"NodeText"
withsubnodes=STRING|"1"
xml00000000=STRING|"{xml}"
xmlcount=STRING|"2"

[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action6\Params]
message=STRING|"{nodeName} : {NodeText}"
type=STRING|"3"

[Actions\Action7]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Oleg Yershov
gremlin
Posts: 50
Joined: Sun Jan 08, 2023 3:13 pm

Re: XML Get Node

Post by gremlin »

Thank you,
I would like to read the individual values ​​into variables in order to create a CSV from them.
I can't read any values ​​here:
Snipaste_2024-11-12_15-19-37.jpg
Snipaste_2024-11-12_15-19-37.jpg (38.27 KiB) Viewed 3891 times
Snipaste_2024-11-12_15-19-46.jpg
Snipaste_2024-11-12_15-19-46.jpg (26.36 KiB) Viewed 3891 times
Oleg
Site Admin
Posts: 3132
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: XML Get Node

Post by Oleg »

These nodes have no attributes
You must read node values (node text)

Also I don't see the node with name NAME
Only NAME2 and NAME3
Oleg Yershov
gremlin
Posts: 50
Joined: Sun Jan 08, 2023 3:13 pm

Re: XML Get Node

Post by gremlin »

OK, thank you
Post Reply