Page 1 of 1
Globally Adding a Random ID Attribute?
Posted: Fri Mar 24, 2023 6:34 pm
by binar
I am using OxygenXML Editor. And I have a procedural data module that is 140 pages long when the XML file is converted to a PDF. The BREX I am using requires each ProceduralStep Tag include an Attribute ID comprised of a 6 digit random number. If this Attribute ID is left out the XML file does not validate without getting a bunch of errors. In short, the tag needs to look like what is shown in the example below:
Does OxygenXML Editor have a tool that targets all "proceduralstep" tags and automatically adds a random 6 digit number as an ID attribute? I have taken a look at the Refactoring toolset but I cannot find any way to generate the 6 digit random number. Any help will be greatly appreciated.
Re: Globally Adding a Random ID Attribute?
Posted: Fri Mar 24, 2023 7:04 pm
by chrispitude
Hi binar,
Oxygen does provide some ID attribute tools, but I'm not sure about your requirements because XML @id attributes cannot begin with a number.
Re: Globally Adding a Random ID Attribute?
Posted: Sat Mar 25, 2023 5:22 am
by binar
My mistake. You are correct. I forgot about the XML rule that requires an ID attribute start with a letter. So allow me to ask my question a different way. Does OxygenXML Editor have a tool that targets all "proceduralstep" tags and automatically adds an XML approved ID attribute using Letters and Numbers? In short, can OxygenXML automatically add the Attribute ID's shown below so it includes: id=" Para0001", id=" Para0002", id=" Para0003", id=" Para0004", and id=" Para0005" with no repeats?
Code: Select all
<proceduralStep Id="Para0001">
<para>Para Level 1</para>
<proceduralStep Id="Para0002">
<para>Para Level 2</para>
<proceduralStep Id="Para0003">
<para>Para Level 3</para>
<proceduralStep Id="Para0004">
<para>Para Level 4</para>
<proceduralStep Id="Para0005">
<para>Para Level 5</para>
</proceduralStep>
</proceduralStep>
</proceduralStep>
</proceduralStep>
</proceduralStep>
Re: Globally Adding a Random ID Attribute?
Posted: Sat Mar 25, 2023 4:44 pm
by chrispitude
Hi binar,
Try running the
Generate IDs refactoring operation (
Tools > XML Refactoring). For the
Element pattern, enter the element name:
In the
Scope and Filters dialog, set the scope to what you want. For example, to run on all .xml files in a particular directory, you would first select that directory in the
Project view, then you would set the scope to
Selected project resources and the Include files filter to *.xml.
The main refactoring operation dialog lists many operations, but it also has a handy search bar that I recommend you use. You can just type in "ID" or "delete" or some other word related to what you want to do, and it should be easy to find the operation you want.
Note that the generated
@id attribute will be lowercase, which is the XML convention. If you need it to be uppercase as in your example, you can use the
Rename Attribute refactoring operation afterward.
- Chris