Skip to content

How to Edit XML

Robert Jordan edited this page Aug 24, 2017 · 4 revisions

How to Edit XML

XML stands for eXtensible Markup Language. It's designed to store and transport data as well as be both human- and machine-readable.

For all intensive purposes of editing ItemModifications.xml, your XML file should always start with this:

<?xml version="1.0" encoding="UTF-8"?>

Tags and Elements

XML is a collection of elements, which are comprised of opening and closing tags. Tag names are case-sensitive. An element includes the open tag, the close tag, and everything inside of it.

  • <Name> denotes the open tag.
  • </Name> denotes the close tag.
  • <Name/> denotes an open and close tag and is a whole element.
  • <Name></Name> denotes an open and close tag and is a whole element.

All open tags must be closed by the end of the file or else the XML cannot be read.

Tag Containment

Elements can be placed inside of each other like such. Elements can also have values inside them.

<?xml version="1.0" encoding="UTF-8"?>
<ItemList>
  <ItemElement>
    <Value/>
    <AnotherValue>0</AnotherValue>
  </ItemElement>
  <ItemElement>
    <Value/>
    <AnotherValue>5</AnotherValue>
  </ItemElement>
</ItemList>

Tag Order

Tags must always be opened and closed in first-in last-out order. For example:

<?xml version="1.0" encoding="UTF-8"?>
<OutsideTag>
  <InsideTag>SomeElementInnerText</OutsideTag>
</InsideTag>

This is incorrect.

<?xml version="1.0" encoding="UTF-8"?>
<OutsideTag>
  <InsideTag>SomeElementInnerText</InsideTag>
</OutsideTag>

While this is correct.


Attributes

Attributes are created by declaring and defining a variable within an element's open tag. Attribute values must be defined within quotes. Attribute names are case-sensitive. Both of the examples below are correct.

<OpenTag AttributeName="AttributeValue"></OpenTag>
<OpenCloseTag AnotherName="AnotherValue"/>

Multiple Attributes

Multiple attributes can be assigned to the same element.

<Food Name="Apple" Color="Red"/>

Comments

Comments are defined by the opening tag of <!-- and the closing tag of -->. Everything within a comment is ignored by XML when being read. Comments cannot be started within a tag. Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
  <!--This is a comment-->
  <!--This comment stretches across multiple lines
  <IgnoredOpenTag>
  The comment is closed here-->
</Root>

Escape Codes

Escape codes are necessary in order to use certain characters when they already have another use as defined by XML. Escape codes are defined by an opening & and a closing ;. Below are all of the relevant escape codes.

Code Character
&quot; " (Double-quote)
&amp; & (Ampersand)
&apos; ' (Single-quote)
&lt; < (Less than)
&gt; > (Greater than)
&#10; Line break
&#nnnn; Decimal Unicode
&#xhhhh; Hex Unicode