Replace/change line in xml file - Forum

Forum Navigation
You need to log in to create posts and topics.

Replace/change line in xml file

Hello All,

I have an question about replacing or changing one or multiple line(s) in an xml file. Below a part of the xml file.
I want to replace or change the value of  <FilterColor>0,255,0</FilterColor>. The RGB value can be different everytime, and can be multiple times be in the xlm file.

Is there anyway in VisualNEO to open the xlm file and replace the value of these <FilterColor> elements.

Best regards,

Eric Beerhorst

 

 

 

<Command>
<Type>Graphics</Type>
<Description>Graphics: Rectangle.png [SVR134_LOW_2:5EF501039_Present]</Description>
<FileName>Rectangle.png</FileName>
<X>1290</X>
<Y>760</Y>
<Width>70</Width>
<Height>130</Height>
<FilePath>C:\Program Files\Myprogram\Graphics\Rectangle.png</FilePath>
<FilterColor>0,255,0</FilterColor>
</Command>
<Command>
<Type>Graphics</Type>
<Description>Graphics: Rectangle.png [SVR134_LOW_2:5EF501039_Present]</Description>
<FileName>Rectangle.png</FileName>
<X>480</X>
<Y>760</Y>
<Width>70</Width>
<Height>130</Height>
<FilePath>C:\Program Files\Myprogram\Graphics\Rectangle.png</FilePath>
<FilterColor>0,255,0</FilterColor>
</Command>

Hey.
The XML file can be edited in any text editor, and can also be edited with VisualNeo.

Best regards,

as3856

 

Hello,

I assume you are asking to do it by code.

I would check 2 Options.

Find and repace with regular expressions.

XML parsing with newlisp.

Regards

Hans-Peter

Eric:

This script might help you to understand how to make changes to text files (as stated above, XML files are just plain text files) ...

... these two variables can be populated via script or can be part of variables associated with TextEntry objects
SetVar "fromColor]" "!0,255,0"
SetVar "[toColor]" "!80,A0,C0"

SetVar "[fromString]" "!<FilterColor>[fromColor]</FilterColor>"
SetVar "[toString]" "!<FilterColor>[toColor]</FilterColor>"


FileRead "[PubDir]myFile.xml" "All" "[myXmlContent]"


StrReplace "[myXmlContent]" "[fromString]" "[toString]" "[myXmlContent]" ""

FileWrite "[PubDir]myFile.xml" "All" "[myXmlContent]"

 

 

luiz has reacted to this post.
luiz