Jump to content

Recommended Posts

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
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
Posted

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>

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...