Globally Adding a Random ID Attribute?

Having trouble installing Oxygen? Got a bug to report? Post it all here.
binar
Posts: 26
Joined: Wed Apr 10, 2019 7:43 pm

Globally Adding a Random ID Attribute?

Post 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:

Code: Select all

<procedrualStep id=583729/>
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.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Globally Adding a Random ID Attribute?

Post 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.
binar
Posts: 26
Joined: Wed Apr 10, 2019 7:43 pm

Re: Globally Adding a Random ID Attribute?

Post 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>
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Globally Adding a Random ID Attribute?

Post by chrispitude »

Hi binar,

Try running the Generate IDs refactoring operation (Tools > XML Refactoring). For the Element pattern, enter the element name:

Code: Select all

proceduralStep
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
Post Reply