File: using.xml

package info (click to toggle)
libgroboutils-java 5-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,396 kB
  • ctags: 11,186
  • sloc: java: 59,748; xml: 12,762; sh: 377; perl: 104; makefile: 20
file content (46 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (3)
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
<?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>