XML Editing
The functions for processing XML files or texts with an XML structure can be found in the TextConverter in the area "Actions > XML" on the right side of the main window. With these functions it is possible to edit texts or text files as part of an XML structure. This means that, for example, you can edit the XML structure directly (for example with the actions for deleting or adding elements or attributes) or you can apply actions only in certain tag names, attribute names, attribute values or inner texts.
This tutorial explains all of these options for XML processing with the TextConverter and is divided into the following sections:
- Elements, Tag Names, Attribute Names, Attribute Values and Inner Texts
- Selection of Inner Texts, Tag Names and Elements
- Selection of Attribute Names and Attribute Values
- Actions for XML Processing
- Conversion of Data into the XML Format
If you want to edit texts differently than within an XML structure, you can use the functions to process texts as a whole, to process lines or to process texts within a CSV structure.
Elements, Tag Names, Attribute Names, Attribute Values and Inner Texts
In the TextConverter and in this tutorial, the terms "element", "tag name", "attribute name", "attribute value" and "inner text" are used. So that there are no misunderstandings, we first look at what these terms are used for within the XML structure:
<TagName AttributeName="Attribute Value">Inner Text</TagName>
In this example, we have given each part of the XML structure the name that is used in the TextConverter and in this tutorial for this component. The term "element" is used in the sense of the entire line shown here. "Element" stands for everything that is located between the first < of the opening tag and the last > of the closing tag, including the characters < and >.
Selection of Inner Texts, Tag Names and Elements
All XML actions for editing inner texts, tag names or elements offer the possibility of selecting those inner texts, tag names or elements to which the respective processing should be applied. Since this selection function respectively the available selection options are always the same for all relevant actions, we would like to explain the procedure in general first in order not to have to address it again later in the explanation of each individual action.
Basically, two options are available, depending on whether you want to edit all inner texts, all tag names respectively all elements or only a selection of inner texts, tag names or elements:
- If you would like to apply an action to all inner texts, tag names or elements, you can simply activate the checkbox "All inner Texts" respectively "All Tag Names" or "All Elements" of the respective action.
- If, on the other hand, you only want to apply the action to certain inner texts, tag names or elements, you can define a selector for the corresponding nodes in the XML structure.
The selectors supported by the TextConverter widely correspond to the usual CSS selectors, which can be used, for example, in HTML documents for assigning CSS rules. As in CSS, several of these selectors can be listed together separated with a comma.
- The simplest selector is the Type Selector and simply consists only of the name of the element. For example, if we want to edit all h1 elements of an HTML document with the TextConverter, we can simply use "h1" as the selector. If we would also like to edit the h2 and h3 elements at the same time, we could use "h1,h2,h3" as a selector.
- With the Universal Selector * we can select all elements. This selector corresponds to the activation of the option "All inner Texts" respectively "All Tag Names" or "All Elements".
- With the ID Selector we can select all elements with a specific ID attribute. To do this, we have to prepend a diamond (#) to the name of the ID, for example #id for all elements with "id" as ID such as <div id="id">.
- The Class Selector works similarly, with which we can select all elements with a certain class attribute. This time, however, we use a point, for example .class for all elements having "class" as a class attribute. For example, if we want to select all p-elements with the class "x", we can use the selector "p.x" (a match would be, for example, <p class="x">).
So far regarding the simplest selectors. Of course, you can additionally also use many of the other well-known selectors with the TextConverter, such as selectors that choose elements based on specific characteristics of their attributes or selectors that refer to the position of an element in the XML structure. However, explaining all of these selectors would go beyond the scope of this tutorial.
Selection of Attribute Names and Attribute Values
Also the actions for editing attribute names and attribute values within an XML structure offer the opportunity to limit the processing to the attributes of certain elements. Here, too, either a limiting selector can be specified for the elements to be processed or the option "All Elements" can be activated to select the attributes of all elements. The functionality of this element selection is identical to the selection of elements for the processing of inner texts, tag names and elements that we have discussed in the last section.
In addition to this element selection, the actions for processing attribute names and attribute values also offer another way to limit the processing to specific attributes: the selection via the attribute name. Again, there is the possibility to specify one or more attribute names to which the processing should be limited, or to select the "All Attribute Names" option.
Let's take a look at four examples demonstrating this:
- If you want to edit all attributes in your XML structure without any exception, regardless of their names and the elements in which the attributes are located, you can accordingly activate both options, "All Elements" and "All Attribute Names".
- If you want to edit all class attributes, regardless of the elements in which these attributes are in, you can specify "class" as attribute name and activate the option "All Elements".
- If you want to edit all attributes of all p-elements, regardless of which attribute it is about, you can enter "p" as a selector and select the "All Attribute Names" option.
- If you want to edit all of the "class" and "style" attributes of p-elements that are located within a div element with the class "x", you can specify "div.x>p" as selector and "class,style"as attribute names.
As you can see, the function for selecting elements and attributes is very powerful and enables almost any restriction of the processing to your desired elements and attributes.
Actions for XML Processing
The following actions are available for XML editing in the current version of the TextConverter:
- Replace in Inner Texts, Tag Names, Attribute Names and Attribute Values
- Delete Text from Inner Texts, Tag Names, Attribute Names and Attribute Values
- Delete Elements
- Delete Attributes
- Trim Inner Texts, Tag Names, Attribute Names and Attribute Values
- Prepend and Append Text to Inner Texts, Tag Names, Attribute Names and Attribute Values
- Insert Text into Inner Texts, Tag Names, Attribute Names and Attribute Values
- Add Elements
- Add Attributes
- Change (upper and lower case) writing of Inner Texts, Tag Names, Attribute Names and Attribute Values
- Change Number Format of Inner Texts and Attribute Values
- Action Lists
In order to limit the scope of these actions to certain inner texts, tag names, elements, attribute names or attribute values, please note the two sections Selection of Inner Texts, Tag Names and Elements as well as Selection of Attribute Names and Attribute Values.
Conversion of Data into the XML Format
With the help of the TextConverter, you can not only edit existing XML data, but also convert non-XML data into the XML format. The functions in this regard can be found in the TextConverter under "Actions > Format". For example, there is a function for the conversion of CSV data into the XML format. With this function, the fields of the CSV data can be integrated either as nodes or as attributes into the XML structure.