Page 1 of 1

Search and replace multiple strings of text

Posted: Sun Jan 05, 2014 7:33 pm
by larsbachs
Hello,

I'm fairly new to the Oxygen XML Editor and not sure if what I want to achieve is possible at all. My case is that I have an increasing list of text strings. Each of the text strings need to be replaced by another text string. This I need to do on a number of XML files. An example could look like this:

If text string "aaa" exists, replace with text string "bbb"

then

If text string "ccc" exists, replace with text string "ddd"

then

If text string "eee" exists, replace with text string "fff"

etc. etc.

Is it possible to do this in Oxygen and if so can you advice how?

Re: Search and replace multiple strings of text

Posted: Mon Jan 06, 2014 5:30 pm
by Costin
Hello,

Currently, it is possible in oXygen to perform a search for multiple words / strings, using a regex.
Eg.: (word1|word2|word3|....wordn).
Unfortunately however, you can only replace all the searched values with a single one. Replacing multiple words with different predefined ones from a group of values (like mapping in pairs the words in the search field with the words in the replace field) is not possible.

Yet, in case you perform find & replace for a specific word, oXygen keeps both the word you've searched for and the replacement word used. Hence, the next time you would perform find & replace, you could choose the replacement word you need from the list of suggestions in oXygen's Find and Replace dialog under History (clock-like icon).
As you might have already figured it out, this however implies to first search once for the words you need to find ("aaa", "ccc" etc.) and apply the replacements as you want ("bbb", "ddd"). In other words, for oXygen to remember those words, you should perform all those steps manually first.

Even so, this could be most probably done by developing a style sheet to do that for you and this requires XSLT development skills.

Regards,
Costin

Re: Search and replace multiple strings of text

Posted: Tue Jun 09, 2015 1:31 pm
by Sybar
Hi,

I'm also new to Oxygen XML Editor.

Since the original post and answer are from January last year maybe a new function has been introduced which would allow to map an XML file containing 'list of lists'; search for specific values and replace them with different ones. Let me explain in more detail...

My XML file contains multiple sets of:

Code: Select all

<drop_lists>
<death>
<group chance="70">
<item id="57" min="11913" max="24348" chance="100"/>
<!-- Adena -->
</group>
<group chance="6.627699851989746">
<item id="13143" min="1" max="1" chance="0.0417"/>
<!-- Sealed Vesper Helmet -->
<item id="13144" min="1" max="1" chance="0.0417"/>
<!-- Sealed Vesper Leather Helmet -->
<item id="13145" min="1" max="1" chance="0.0417"/>
<!-- Sealed Vesper Circlet -->
<item id="14111" min="1" max="1" chance="0.0596"/>
<!-- Sealed Vesper Shield -->
<item id="13887" min="1" max="1" chance="0.0596"/>
<!-- Sealed Vesper Sigil -->
<item id="15660" min="1" max="1" chance="16.7489"/>
<!-- Sealed Vesper Helmet Piece -->
<item id="15661" min="1" max="1" chance="16.7489"/>
<!-- Sealed Vesper Leather Helmet Piece -->
<item id="15662" min="1" max="1" chance="16.7489"/>
<!-- Sealed Vesper Circlet Piece -->
<item id="15669" min="1" max="1" chance="24.7544"/>
<!-- Sealed Vesper Verteidiger Piece -->
<item id="15691" min="1" max="1" chance="24.7546"/>
<!-- Sealed Vesper Sigil Piece -->
</group>
<group chance="36.0182991027832">
<item id="1879" min="1" max="3" chance="43.0384"/>
<!-- Cokes -->
<item id="1885" min="1" max="1" chance="43.0384"/>
<!-- High-Grade Suede -->
<item id="9628" min="1" max="1" chance="4.0507"/>
<!-- Leonard -->
<item id="9630" min="1" max="1" chance="2.7182"/>
<!-- Orichalcum -->
<item id="9629" min="1" max="1" chance="2.2455"/>
<!-- Adamantine -->
<item id="14166" min="1" max="1" chance="2.495"/>
<!-- Life Stone - Level 84 -->
<item id="14167" min="1" max="1" chance="0.623"/>
<!-- Mid-Grade Life Stone - Level 84 -->
<item id="14168" min="1" max="1" chance="0.0623"/>
<!-- High-Grade Life Stone - Level 84 -->
<item id="15792" min="1" max="1" chance="0.2951"/>
<!-- Recipe - Sealed Vesper Helmet (60%) -->
<item id="15793" min="1" max="1" chance="0.2951"/>
<!-- Recipe - Sealed Vesper Leather Helmet (60%) -->
<item id="15794" min="1" max="1" chance="0.2951"/>
<!-- Recipe - Sealed Vesper Circlet (60%) -->
<item id="15808" min="1" max="1" chance="0.4216"/>
<!-- Recipe - Sealed Vesper Shield (60%) -->
<item id="15807" min="1" max="1" chance="0.4216"/>
<!-- Recipe - Sealed Vesper Sigil (60%) -->
<item id="10578" min="1" max="1" chance="0.0500"/>
<!-- Forgotten Scroll - Mutual Response -->
<item id="14191" min="1" max="1" chance="0.0500"/>
<!-- Forgotten Scroll - Meteor -->
</group>
<group chance="7">
<item id="15690" min="1" max="1" chance="15"/>
<!-- Secret Key -->
<item id="15540" min="1" max="1" chance="15"/>
<!-- Unlit Torchlight -->
<item id="8056" min="1" max="1" chance="70"/>
<!-- Key of Splendor Room -->
</group>
<group chance="16.0">
<item id="8603" min="1" max="1" chance="50"/>
<!-- Herb of Mana -->
<item id="8604" min="1" max="1" chance="50"/>
<!-- Greater Herb of Mana -->
</group>
</death>
Individual <itemd id="xxxx"....> are childs of <group chance="xx">

What I would like to do is to change values in <item id=....chance="xxxx"/> with different ones. I've already tried to do that in Excel. It all looked promissing as Excel allows me to map an XML file and then pair up <group chance="xx"> with <itemd id="xxxx"....> in a form of two adiecent tables.

The only problem is, because my XML file contains parent and child categories (List of Lists) my work cannot be exported; Excel cannot handle that type of export.

A sample:

<group chance="70">
<item id="57" min="11913" max="24348" chance="100"/>
<!-- Adena -->
</group>

Can oXygen XML Editor 'look' through my XML file and pair xx with xxx and then allow me to change all sub values xxx to different ones. I would like to change many at once. Or simply find all xxx and replace them with different values?

Thanks

Re: Search and replace multiple strings of text

Posted: Wed Jun 10, 2015 11:20 am
by florin
Hello,

I'm not sure if what I understood is exactly what you want, so please correct me if I'm wrong.

So, you would like to define a find/replace mapping containing two sets: one set of "values to be replaced" and another set containing the "values to replace with". If this is the case, then this is not possible in oXygen - at least, not through a dedicated operation.

But, you could achieve this through other possibilities that involve running some operations mutiple times:
  1. oXygen 17 comes with a new tool - XML Refactoring.
    The XML Refactoring wizard allows you to perform different operations that perform changes in XML files, like:
    • adding, deleting, inserting, renaming and (un)wrapping elements (or only element content for some of them);
    • adding, deleting, renaming setting and changing values of attributes;
    • inserting XML fragments or replacing elements (or content of elements) with XML fragments.
    Thus, you could use this wizard to perform multiple attribute value changes. Just open the XML Refactoring wizard from the Tools menu and select the Add/Change attribute operation. After, you'll have to specify the name of the elements that contain the attribute you are interested in and the new value to be set for that specific attribute.
    What you cannot do with this operation is to specify a more complex "search" pattern, in case you want to replace the attribute values of item elements belonging to a group with a specific chance value.
  2. You can use the Find/Replace dialog box. It allow you to use XPath expressions, thus you can identify the item elements that you want to modify using a more complex expression, like:

    Code: Select all

    
    Find: \".*\"
    Replace with: "NEW_VALUE"
    XPath: //group[@change='SPECIFIC_VALUE_IF_NEEDED']/item/@chance
    After pressing the Find all button, oXygen highlights all locations that match the input Find and XPath values, thus you can check if the replace will take place only on the desired elements.
Best regards,
Florin