User:Pangaearocks/Code snippets

Code snippets
PS:  requires Page Forms.

0 }}

% }}

Xmlstarlet
Write this down quickly before I forget or ruin the code, which actually works: xmlstarlet sel -t -m "//redxml/definitions/items/item/tags[text[contains(.,'Edibles')]]/parent::item" -s A:T:- "@name" -v "concat('* ',@name)" -nl ALL_ITEMS.xml > alledibles.txt

This appears to do the same, so both variants can be used, depending on the need: xmlstarlet sel -t -m "//redxml/definitions/items/item/tags[text[contains(.,'Edibles')]]" -s A:T:- "../@name" -v "concat('* ',../@name)" -nl ALL_ITEMS.xml > alledibles.txt

Code for getting data from XML-file categories (categories have one value): xmlstarlet sel -t -m "//redxml/definitions/items/item[@category='edibles']" -s A:T:- "@name" -v "concat('* ',@name)" -nl ALL_ITEMS.xml > alledibles.txt Sometimes that isn't enough, or it is better to use tags for more precise selection.

This selects the XML of the whole node ( to  ) xmlstarlet sel -t -m '//redxml/definitions/abilities/ability[@name="'"Boots 02 _Stats"'"]' -c. ALL_ITEMS.xml

This could come in handy:
 * XPath: Get parent node from child node
 * How to find element using contains in xpath

Used to generate item list (damn it's many!): category: alchemy_ingredient crafting_ingredient crossbow bolt potion petard oil upgrade dye junk

tags: PlayerSilverWeapon PlayerSteelWeapon Armor Skip recipes and such for now...