Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulate Value in XML File
Been a while since I've used QM and could use some help finding the right approach for this task:

in a target XML file, I need to find every line that contains <string name="Path" and then change its value from a PC path to a Mac path.

For example, the following line will appear many times in an XML file:

<string name="Path" value="X:\AUDIO PROJECTS\TestFolder\"/>

For each one, I need to
A) replace the PC drive name X: in the value field with its Mac equivalent /Volumes/AUDIO SSD
B) turn all the backslashes in the value field into forward slashes, so each occurrence now looks like this:

<string name="Path" value="/Volumes/AUDIO SSD/AUDIO PROJECTS/TestFolder/"/>

Note: The PC drive name "X:" and replacement Mac equivalent "/Volumes/AUDIO SSD" will always be used in the XMLs I need to process, but the rest of the path will change from XML to XML.

I think I can probably figure it out eventually, but some help getting started would be appreciated. How to find and each line with "<string name="Path"" and load whole line to manipulate, or is there a simple way using QM XML tools to get the value for Path each time it occurs and then I can manipulate its value? Been too long...

Macro Macro2315
Copy      Help
str s=
;<string name="Path" value="X:\AUDIO PROJECTS\TestFolder\"/>
;<string name="Path" value="X:\AUDIO PROJECTS\TestFolder2\"/>

IXml x._create

ARRAY(IXmlNode) a; int i
x.RootElement.GetAll(0 a)
for i 0 a.len
,IXmlNode n=a[i]
,if(StrCompare(n.Name "string")) continue
,if(!s.begi("X:\")) continue
,s.findreplace("\" "/")
,s.replace("/Volumes/AUDIO SSD" 0 2)

x.ToString(_s); out _s

Or use regular expression, but may be not easy to make reliable.
Perfect, thank you sir!

Forum Jump:

Users browsing this thread: 1 Guest(s)