cancel
Showing results for 
Search instead for 
Did you mean: 

XML key/value pairs (Utility - XML)

Walter.Koller
Level 11
Hi,

I wanted to parse some data from XML file and thought to use the Utility - XML provided by Blue Prism.
Soon I came to the point where it seems the VBO cannot help me anymore.

I used following file: 
C:\Program Files\Blue Prism Limited\Blue Prism Automate\Automate.exe.config

And want to read the value of this line:
<add key="BrowserAutomation.DefaultCommunicationTimeout" value="3000" />

The action Get Attribute returns only: 
value=

It seems Utility - XML expects a format like: 
<key name="k1">val1</key>
but got this:
<item key="k1" value="val1" />

There seem to be three ways on presenting key/value pairs in XML:
https://stackoverflow.com/questions/1543388/xml-dom-storing-key-value-pairs

I looked at DX if there is a newer version available but the VBO handles key/values the same way.
(btw the version number in DX is 1.0.0 but the file is named BPA+Object+-+Utility+-+XML_v2.0.xml and was updated two days ago.
Also the link to the readme.md file does not work anymore)

Is this a community topic or should I create support ticket?


------------------------------
Walter Koller
Solution Manager
Erste Group IT International GmbH
Europe/Vienna
------------------------------
1 BEST ANSWER

Helpful Answers

@Walter Koller,

I just took a look at this and it seems to work fine. Here's how I get the key name and key value using the Get Attributes action:
  1. I started by reading the contents of the config file.
  2. Then a pulled a collection of the <add /> elements.
  3. Next, I iterate over the rows of the collection pulling the values for the two attributes named key and value.
11986.png
BTW - We've fixed the documentation and version issues too.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

View answer in original post

10 REPLIES 10

ewilson
Staff
Staff
Hi @Walter Koller,

Go ahead and open a ticket on this. That way we'll have some tracking on it.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

@Walter Koller,

I just took a look at this and it seems to work fine. Here's how I get the key name and key value using the Get Attributes action:
  1. I started by reading the contents of the config file.
  2. Then a pulled a collection of the <add /> elements.
  3. Next, I iterate over the rows of the collection pulling the values for the two attributes named key and value.
11986.png
BTW - We've fixed the documentation and version issues too.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

@ewilson
Thanks a lot for your quick and working ​solution.
There would be also a decision necessary to manually verify if the KEY is the one I am looking for.
This should work, although it is a little more complex than using the Get Attribute action once and getting exactly the value what I am looking for.

I did another test with XML document containing all three format. This one should be supported by the Get Attribute action:
<key name="v3k1">v3val1</key>
However, when executing this stage with Attribute Name = "v3k1" the result is: 
v3val1</key>
I did another test by changing the line in the XML document to:
<key name="v3k1">"v3val1"</key>
But this didn't return any result at all.

When looking at the Utility - XML code for Get Attribute:
//Attribute holds the value provided to the action: v3k1
i += Attribute.length + 2 //i is set to the character after: v3k1">
value = XML.substring(i) //value is set to: v3val1</key>
value = value.substring(0, value.indexof("""")) //right side of value is truncated to the first "
//if value = "v3val1"</key> then the result is " (I guess single " will be ignored in BP the result is therefore empty)
//if value = v3val1</key> then the result is v3val1</key> (ie until EOL) since no " is found

or did I miss something?

------------------------------
Walter Koller
Solution Manager
Erste Group IT International GmbH
Europe/Vienna
------------------------------

@Walter Koller,

I think there's a little misunderstanding here. In terms of the XML specification, the two items key and value are nothing more than attributes on the add element. They could just as easily be named john and doe.​ If you know the name of the attribute and you use the Get Attribute action you will get the exact value of that attribute.

In your example, <key name="v3k1">v3val1</key>, the parts of the XML are as follows:

  • <key ...>...</key> is an XML element
  • name="v3val1" is an attribute of the element <key>...</key>
  • v3val is the value of the element <key>...</key>
  • v3k1 is the value of the attribute name
Here's an example, using your test XML, of one way of retrieving the specific element variant3 and then parsing its child elements and their associated attributes:

11988.png
11989.png
11990.png
11991.png
11992.png
11993.png
11994.png
Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

@ewilson
Hi Eric, thanks a lot for taking your time for explaining what the knot in my thinking is.
It seems I found a very bad and confusing example of XML for testing the VBO.
For me KEY and its VALUE is basically one entity, thus I was assuming the meaning of the structure instead of reading the actual syntax. Thanks for pointing this out 🙂

------------------------------
Walter Koller
Solution Manager
Erste Group IT International GmbH
Europe/Vienna
------------------------------

Hello @ewilson,

I tried to implement your solution for the below XML format. But, I am not able to get the value which is corresponding to "id" and "cycle-id". Could you please help me with the same ?

<Field Name ="id" ><Value>12345<Value></Field>
<Field Name ="cycle-id" ><Value>67891<Value></Field>
 Thanks in Advance!​

Kind Regards,

------------------------------
Kiran Singh
------------------------------

Hello @KiranSingh,

First issue is that your XML is not valid. The Value elements are not properly terminated. They should be defined as <Value>...</Value>. Your missing the forward slash on the closing tag.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hello @ewilson,

Thanks for highlighting the syntax error.​  This was a typing error on my side in the chat. Could you please suggest a solution to fetch value against "id and "cycle -id"?

XML after correction :
<Field Name ="id" ><Value>12345</Value></Field><Field Name ="cycle-id" ><Value>67891</Value></Field>​


------------------------------
Kiran Singh
------------------------------

@KiranSingh,

Is the XML that you're working with part of a larger document? The snippet that you've shown in your example probably isn't being processed because there's no root/container element. You just have two Field elements at the same level. If you wrap your example XML in a container element then you can call Get Elements and it will return a Collection with two records (each of the Field elements).

Here's an example of what the XML should look like:
<Fields>
  <Field Name ="id" >
    <Value>12345</Value>
  </Field>
  <Field Name ="cycle-id" >
    <Value>67891</Value>
  </Field>
</Fields>​


And here's what my Get Elements call looks like:
12008.png

And this is what the output Collection looks like after calling Get Elements:
12009.png
After that, you can loop the Collection to pull out the value of the Name attribute using the Get Attribute action: 
12010.png
And then you can use XPath to pull out the Value element contained within the Field element:
12011.png
This is what the output Collection looks like for that:
12012.png
Finally, you have an internal loop (loop within the outer loop) to loop over the Value Collection. Put it all together and it looks something like this:
12013.png
Cheers,



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------