Page 1 of 1

Please Help

Posted: Tue Apr 20, 2010 6:25 pm
by motili
Im have one xml file and im need update the price values on it reading new values from text or another xml file!How this can be done with oxygen editor? Here is example:(the full xml is 15 mb)

Code: Select all

<item_template id="100000001" level="1" mask="562" weapon_type="SWORD_1H" max_stack_count="1" item_type="normal" quality="COMMON" [b]price="5"[/b] race="ALL" can_proc_enchant="true" no_enchant="true" option_slot_bonus="0" desc="1401117" attack_gap="0.0" attack_type="physical" dmg_decal="1" slot="3" equipment_type="WEAPON">
<modifiers>
<set name="ATTACK_SPEED" value="1400"/>
<add name="PARRY" value="173"/>
<add name="PHYSICAL_CRITICAL" value="50"/>
<add name="MIN_DAMAGES" value="16"/>
<add name="MAX_DAMAGES" value="20"/>
<mean name="POWER" min="16" max="20"/>
<set name="ATTACK_RANGE" value="1500"/>
<set name="HIT_COUNT" value="2"/>
</modifiers>
</item_template>
<item_template id="100000002" level="1" mask="562" weapon_type="SWORD_1H" max_stack_count="1" item_type="normal" quality="COMMON" [b]price="5"[/b] race="ALL" can_proc_enchant="true" no_enchant="true" option_slot_bonus="0" desc="1401145" attack_gap="0.0" attack_type="physical" dmg_decal="1" slot="3" equipment_type="WEAPON">
<modifiers>
<set name="ATTACK_SPEED" value="1400"/>
<add name="PARRY" value="173"/>
<add name="PHYSICAL_CRITICAL" value="50"/>
<add name="MIN_DAMAGES" value="16"/>
<add name="MAX_DAMAGES" value="20"/>
<mean name="POWER" min="16" max="20"/>
<set name="ATTACK_RANGE" value="1500"/>
<set name="HIT_COUNT" value="2"/>
</modifiers>
</item_template>
here is example of the new values another xml file:

Code: Select all


<item_template>
<item_template id="100000001"
price="500">
</item_template>
<item_template>
<item_template id="100000002"
price="10">
</item_template>
Im absolutely new on xml programming!Thx in advance...

Re: Please Help

Posted: Fri Apr 23, 2010 3:13 pm
by adrian
Hello,

You should have probably started with XSLT stylesheets but I had an XQuery Update lying around that can help you. All I had to do was to make small adjustments to the XPath to fit your case.

process.xquery

Code: Select all

for $i in doc("input.xml")//item_template
let $j := doc("newPrice.xml")//item_template[@id=$i/@id]
return if (not(empty($j)))
then replace node $i/@price with $j/@price
else ()
WARNING: Be careful when executing this query because it modifies the source file ('input.xml') so make sure you have a backup of it. Normally an XQuery reads from a source file, processes and generates output, but XQuery Update works on the input, just like an SQL update command works on a database.

So, to execute the query in Oxygen you should first save it in an XQuery file(File -> New -> XQuery) in the same folder you have the xml files.
Create a new transformation scenario(Document -> Transformation -> Configure Transformation Scenario, New), give it a name and choose from the Transformer combo Saxon-EE. OK in all dialogs, and transform it(Document -> Transformation -> Apply Transformation Scenario).

Regards,
Adrian

Re: Please Help

Posted: Fri Apr 23, 2010 10:04 pm
by motili
Thank you very much for your help!The query is working just the format of the xml file has been changedand now the price node is in end of the file!Maybe im do something wrong? Here is the Example of the old and the new(transformed) file:

Old xml format:

Code: Select all

	<item_template id="100000001" level="1" mask="562" weapon_type="SWORD_1H" max_stack_count="1" item_type="normal" quality="COMMON" price="5" race="ALL" can_proc_enchant="true" no_enchant="true" option_slot_bonus="0" desc="1401117" attack_gap="0.0" attack_type="physical" dmg_decal="1" slot="3" equipment_type="WEAPON">
<modifiers>
<set name="ATTACK_SPEED" value="1400"/>
<add name="PARRY" value="173"/>
<add name="PHYSICAL_CRITICAL" value="50"/>
<add name="MIN_DAMAGES" value="16"/>
<add name="MAX_DAMAGES" value="20"/>
<mean name="POWER" min="16" max="20"/>
<set name="ATTACK_RANGE" value="1500"/>
<set name="HIT_COUNT" value="2"/>
</modifiers>
</item_template>
New Transformed Xml:

Code: Select all

    <item_template id="100000617" level="50" mask="48" weapon_type="SWORD_1H" max_stack_count="1"
item_type="abyss"
quality="UNIQUE"
aic="62"
ai="186000030"
ap="614800"
race="ALL"
can_proc_enchant="true"
option_slot_bonus="0"
desc="1457073"
attack_gap="0.0"
attack_type="physical"
dmg_decal="1"
slot="3"
equipment_type="WEAPON"
price="1500000000">
<modifiers>
<set name="ATTACK_SPEED" value="1400"/>
<add name="PHYSICAL_ACCURACY" value="804"/>
<add name="MAGICAL_ACCURACY" value="260"/>
<add name="PARRY" value="736"/>
<add name="PHYSICAL_CRITICAL" value="50"/>
<add name="MIN_DAMAGES" value="151"/>
<add name="MAX_DAMAGES" value="185"/>
<mean name="POWER" min="151" max="185"/>
<set name="ATTACK_RANGE" value="1500"/>
<set name="HIT_COUNT" value="2"/>
<add name="PHYSICAL_CRITICAL" value="52" bonus="true"/>
<add name="PHYSICAL_ATTACK" value="30" bonus="true"/>
<add name="PVP_ATTACK_RATIO" value="60" bonus="true"/>
</modifiers>
</item_template>
Again Thanks for your Help!

Re: Please Help

Posted: Sun Apr 25, 2010 8:26 pm
by motili
Ok im solve the problem with "replace value of node" and Format and Indent Function!Again thank you very much for your help!