cancel
Showing results for 
Search instead for 
Did you mean: 

How To replace a value of one element in XML?

AyyoubBenoudina
Level 4
Hi Community

I tried to replace a value of one element in my xml Text :
looks like this:

<S:Envelope xmlns:S="http://www.oap-envelope"><S:Envelope xmlns:S="http://www./soap-envelope"> <S:Header> <To xmlns="http://www----------sing"></To> <Action xmlns="http://www.w3.or------------ssing" S:mustUnderstand="true">httpntrag</Action> </S:Header> <S:Body> <ns7:textxy1     xmlns="http://------"     xmlns:ns2="hays"     xmlns:ns3="http://schema------------"     xmlns:ns4="htTO"     xmlns:ns5="htt"     xmlns:ns6="htTO."         > <ns7:input> <textxy2> <Tag1> <a/> <b>36000<b> <c/> <au>0001</au> </c> <d i:nil="true"/> <ElementXY i:nil="true"/>.......

I tried with Blue Prism Code but It didn't work.

My Prorgramming skills are very limited but I tried to do the following:
24549.png

I will appreciate you help.
please show me how we can do it?
thanks and best regards,
Ayyoub

------------------------------
Ayyoub Benoudina
Analyst-Sol Development

------------------------------
4 REPLIES 4

ritansh.jatwani
Level 9
Hi,

Whenever you are getting the error message:

Internal : This code stage could not be run because it was added or modified since the object was started

It simply means you need to reset the code and then run it again. It might be possible while running the process in debug mode, you are applying the changes in the code stage and after the changes are done, you are just testing it without resetting the full code.

------------------------------
Ritansh Jatwani
Consultant
EY
Asia/Kolkata
------------------------------

Hi Ritansh
sorry the message wasn't the right one. I was mistaken.
anyway, do you know how to do it with c#?
how to replace or update elements values of xml?
 Thanks in advance

------------------------------
Ayyoub Benoudina
Analyst-Sol Development
Herr
Europe/Brussels
------------------------------

Hi again,

XSLT is the standard way to transform one XML format to another but this requires much learning to get good at.

in C# you can use the object Xdocument to manipulate XML elements and it looks like you have been trying this from previous posts.

if you don't like the Xdocument coding route then there are always alternatives.  Perhaps reading the XML as a Text data type and performing string matches for the values you wish to change? More risky but more intuitive for a non developer.

if you are comfortable manipulating collections then try to get the XML as a collection, make the changes and serialize back to XML. This requires more C# code stages. I have some that I can send you to help-send me your email directly to peter.lacken@renroros.no.

Hope this is some inspiration and good luck with your automation!
peter 



------------------------------
PeterLacken
Ren Røros Intelligent Automation
Peter.Lacken@rria.no
http://www.rria.no
------------------------------

Hi Peter,

Thanks for your answers.
I tried to do it exactely like mentioned here: https://stackoverflow.com/questions/544310/best-way-to-change-the-value-of-an-element-in-c-sharp
The difference in BluePrism is  that  the XML is read from String Data Item and not from a file.  and It will be updated in a DataItem too.

If I have this xml text saved in a String (InputXML)

<MyXmlType> <MyXmlElement>Value</MyXmlElement> </MyXmlType>

and I want to update the value of elemnt "MyXmlelement"  and save the new text in one Output String Data Item.
Do you know how to do it?

Thanks in advance,
Ayyoub



------------------------------
Ayyoub Benoudina
Analyst-Sol Development
Herr
Europe/Brussels
------------------------------