<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<head>
    <name>Using Util-XML</name>
    <doc-version>$Date: 2003/07/21 21:53:05 $</doc-version>
    <author>Matt Albrecht</author>
</head>
<body>
All you need to use the XML utility is to:
<OL>
    <LI>
    Add this line to the top of your Java source:
<!--
import net.sourceforge.groboutils.util.xml.v1.XMLUtil;
-->
<PRE CLASS="JavaCode"><SPAN CLASS="gutter">1:</SPAN><SPAN CLASS="syntax9">import</SPAN> net.sourceforge.groboutils.util.xml.v1.XMLUtil;
</PRE>
    </LI>
    <LI>
    To convert a string to an XML-formatted string (suitable for including
    in attributes and in-line text):
<!--
String mystring = XMLUtil.getInstance().utf2xml("Some' < \" < Text &.");
-->
    <PRE CLASS="JavaCode"><SPAN CLASS="gutter">3:</SPAN>String mystring <SPAN CLASS="syntax18">=</SPAN> XMLUtil.<SPAN CLASS="syntax6">getInstance</SPAN>().<SPAN CLASS="syntax6">utf2xml</SPAN>(<SPAN CLASS="syntax13">&quot;</SPAN><SPAN CLASS="syntax13">Some</SPAN><SPAN CLASS="syntax13">'</SPAN><SPAN CLASS="syntax13"> </SPAN><SPAN CLASS="syntax13">&lt;</SPAN><SPAN CLASS="syntax13"> </SPAN><SPAN CLASS="syntax13">\&quot;</SPAN><SPAN CLASS="syntax13"> </SPAN><SPAN CLASS="syntax13">&lt;</SPAN><SPAN CLASS="syntax13"> </SPAN><SPAN CLASS="syntax13">Text</SPAN><SPAN CLASS="syntax13"> </SPAN><SPAN CLASS="syntax13">&amp;.</SPAN><SPAN CLASS="syntax13">&quot;</SPAN>);
<SPAN CLASS="gutter">4:</SPAN>StringBuffer sb <SPAN CLASS="syntax18">=</SPAN> <SPAN CLASS="syntax8">new</SPAN> <SPAN CLASS="syntax6">Stringbuffer</SPAN>();
    </PRE>
    The resulting string will be correctly escaped for XML.
    </LI>
    <LI>
    If you want to append XML-formatted text to a string buffer, you can use:
<!--
StringBuffer sb = new Stringbuffer();
XMLUtil.getInstance().utf2xml( mytext, sb );
-->
    <PRE CLASS="JavaCode"><SPAN CLASS="gutter">4:</SPAN>StringBuffer sb <SPAN CLASS="syntax18">=</SPAN> <SPAN CLASS="syntax8">new</SPAN> <SPAN CLASS="syntax6">Stringbuffer</SPAN>();
<SPAN CLASS="gutterH">5:</SPAN>XMLUtil.<SPAN CLASS="syntax6">getInstance</SPAN>().<SPAN CLASS="syntax6">utf2xml</SPAN>( mytext, sb );
    </PRE>
    This may be a bit faster, since it doesn't need to perform a
    <tt>toString()</tt> on an internal <tt>StringBuffer</tt> then append that
    to another <tt>StringBuffer</tt>.
    </LI>
</OL>
</body>
</document>

