Sign in to follow this  
Followers 0
Vijay933

Replacing a Particular TEXT in XML file

3 posts in this topic

#1 ·  Posted (edited)

I would like to know how to replace a particular text which is there across the XML file.

Sample:

<General><id extension="0" [b]root="1.366680386.0" [/b]/></General><Corporate><id extension="0" root="1.366680386.0" /></Corporate>

need to replace the text under the "root". Please share code/suggest how to go ahead

Edited by Vijay933

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Eh, first of this isn't the help section of the forums. Second, i can hardly understand what you mean...I guess you want to replace "1.366680386.0". You either do that with StringRegExpReplace() Or use _StringBetween() which will give you the string(word/number) between two strings. For Example _StringBetween($string,'extension="0" root=', '/>') would return '"1.366680386.0"' You then use that string with StringReplace()

Edited by Datenshi

Share this post


Link to post
Share on other sites

You can use the StringRegExpReplace() function for replacing strings. The best thing to do (if you want to work directly on the xml) is to take a look at the made by Eltorro. The thread has a lot of examples of Autoit working with xml and with this UDF you can use xpath on your xml file. For your specific case it's hard to give a good code example, because you only posted a part of the xml, but you may look at sample below:

Input:

<General>

<Corporate>

<id extension="0" root="1.366680386.0"/>

</Corporate>

<Corporate>

<id extension="0" root="1.366680386.0" />

</Corporate>

</General>

Sample Autoit Code:

#include <_XMLDomWrapper.au3>

$sFile = @ScriptDir & "\sample.xml"

If FileExists($sFile) Then

  $ret = _XMLFileOpen($sFile)
  If $ret = 0 Then Exit
 
  _XMLSetAttrib("//id","root","*")

EndIf

output:

<General>

<Corporate>

<id extension="0" root="*"/>

</Corporate>

<Corporate>

<id extension="0" root="*"/>

</Corporate>

</General>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0