1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>2.
Formatting a Document
</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"><link rel="start" href="index.html" title="
xmlformat Tutorial
"><link rel="up" href="index.html" title="
xmlformat Tutorial
"><link rel="prev" href="introduction.html" title="1.
Introduction
"><link rel="next" href="using-config-file.html" title="3.
Using a Configuration File
"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.
Formatting a Document
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="using-config-file.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="formatting-document"></a>2.
Formatting a Document
</h2></div></div></div><p>
Suppose you have an XML document named <code class="filename">doc1.xml</code>
that looks like this:
</p><pre class="screen">
<event>
<description>I bought a new coffee cup!</description>
<date><year>2004</year><month>2</month><day>1</day></date>
</event>
</pre><p>
Suppose further that you want it to look like this:
</p><pre class="screen">
<event>
<description>I bought a new coffee cup!</description>
<date>
<year>2004</year>
<month>2</month>
<day>1</day>
</date>
</event>
</pre><p>
By happy coincidence, that happens to be exactly the default output
style produced by <span><strong class="command">xmlformat</strong></span>. To reformat your
document, all you have to do is run <span><strong class="command">xmlformat</strong></span> with
the document filename as the argument, saving the output in another
file:
</p><pre class="screen">
% <strong class="userinput"><code>xmlformat doc1.xml > output</code></strong>
</pre><p>
Note: <code class="literal">%</code> represents your shell prompt; do not type it
as part of the command.
</p><p>
If you are confident that the output style produced by
<span><strong class="command">xmlformat</strong></span> will be as you desire, you can be reckless
and perform an in-place conversion:
</p><pre class="screen">
% <strong class="userinput"><code>xmlformat -i doc1.xml</code></strong>
</pre><p>
In this case, <span><strong class="command">xmlformat</strong></span> reads the document from the
input file, reformats it, and writes it back out to the same file,
replacing the file's original contents. If you are not quite so
reckless, use <code class="option">-i</code> in conjunction with a
<code class="option">-b</code> option to make a backup file that contains the
original document. <code class="option">-b</code> takes an argument that specifies
the suffix to add to the original filename to create the backup
filename. For example, to back up the original
<code class="filename">doc1.xml</code> file in a file named
<code class="filename">doc1.xml.bak</code>, use this command:
</p><pre class="screen">
% <strong class="userinput"><code>xmlformat -i -b .bak doc1.xml</code></strong>
</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="using-config-file.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.
Introduction
</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3.
Using a Configuration File
</td></tr></table></div></body></html>
|