I have searched for this for quite a while now, but I have not really reached any answers about how to do this. I am working with an XML-file that is tagged in indesign. It is basically just alot of text with a few words here and there that are tagged. The basic structure is like this:
<text>Hello, My name is <name>Mariel</name> and I am an excellent dancer. Just as good as the more famous <name >Mariel</name> who stole my name.</text>
what I want to do is exchange the words within the <name> tags with something else. The text I am working on is quite large and there are maybe fifty different tags that needs to be recognized and changed (many tags like <name> show up in different parts of the text). So i need some kind of system for it.
I have managed to load the xml file and put the contents of the tags in an String-array and change it like how i want to have it. But I dont know who to write it back to an xml file? What would you guys do if you were facing the same problem?
It is not impossible to do in Processing but I'm pretty sure it would involve quite a lot of work:
1. You are going to have to load the text of the XML file into Processing. Probably using loadStrings()
2. Set up some kind of personal menu or selection method for saying what kind of tag you are looking for. For example, if you selected <name> as the tag you want it would use that as the search string for step 3.
3. Search for your keyword string you picked from step 2. Then build a substring that goes until the ending tag (</name>). The substring would be the text between <name>"text you pulled"</name>.
4. Set up a method of writing a new text that will replace the substring you pulled. For example, if your pulled substring was "Mariel" and your new text was "Bob" it would place "Bob" between the <name></name>. This will require setting up some kind of typing method in Processing to write "Bob".
5. Use save strings to save your new text (the whole thing you originally loaded and modified) and save it with a .xml extension.
Thanks for the replies! Asimes, your solution was the one I was thinking about (but wanted to avoid :)) But maybe that is the best way if one is going to do it in processing. I will check out XSLT and Saxon as mbraendle suggested! If anyone else has any tips, feel free to share :)
If anyone else has the same problem, I solved this by using a DOM XML parser with JAVA. It works just as I wanted. The class attached below is certainly not complete but the basic "replace contents inside tag" works just fine. Thanks for the help guys!