Quantcast
Viewing all articles
Browse latest Browse all 10

How to clean XML files in Linux?

Some programs use a lot of XML files. This is case the for ROS in which the robots are described using the URDF format, which is basically a specific XML format. The robot description can become rapidly huge, even when spitted over several files and optimized with xacro. And sometimes XML files are reused from other projects, aggregated, sliced into several piece, etc. At some point, you may have to clean an XML, meaning reformatting the file to have a consistent indentation.

This can be done with the following command line xmllint --format some_file.xml. This command will output the content of the file, reformatted with a clean indentation. To generate a new file, just do xmllint --format some_file.xml > clean_file.xml.

For example:

	<xacro:macro name="youbot_base" params="name">
		
		<link name="${name}_footprint">
      			<inertial>
        			<mass value="0.1" />
        			<origin xyz="0 0 ${-base_size_z / 2.0}" rpy="0 0 0" />
        			<inertia ixx="1.0" ixy="0.0" ixz="0.0"
                 			iyy="1.0" iyz="0.0" izz="1.0" />
      				</inertial>
      			<visual>
        			<origin xyz="0 0 0" rpy="0 0 0" />
        			<geometry>
          				<box size="0.001 0.001 0.001" />
        			</geometry>
               			<material name="Red" />
      			</visual>
      			<collision>
        			<origin xyz="0 0 ${-base_size_z / 2.0}" rpy="0 0 0" />
        			<geometry>
          				<box size="0.001 0.001 0.001" />
        			</geometry>
      			</collision>
    		</link>

Will become:

  <xacro:macro name="youbot_base" params="name">
    <link name="${name}_footprint">
      <inertial>
        <mass value="0.1"/>
        <origin xyz="0 0 ${-base_size_z / 2.0}" rpy="0 0 0"/>
        <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
      </inertial>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <box size="0.001 0.001 0.001"/>
        </geometry>
        <material name="Red"/>
      </visual>
      <collision>
        <origin xyz="0 0 ${-base_size_z / 2.0}" rpy="0 0 0"/>
        <geometry>
          <box size="0.001 0.001 0.001"/>
        </geometry>
      </collision>
    </link>
Image may be NSFW.
Clik here to view.
xml code cleaning in linux How to clean XML files in Linux?

xml code cleaning in linux

The post How to clean XML files in Linux? appeared first on Zombie Brainz' Juice.


Viewing all articles
Browse latest Browse all 10

Trending Articles