Author: dims
Date: Sat May 6 14:28:09 2006
New Revision: 400372
URL: http://svn.apache.org/viewcvs?rev=400372&view=rev
Log:
don't prettify output even for illustration, use FileInputStream to prevent
problems loading xml files that are not utf-8
Modified:
webservices/commons/trunk/modules/axiom/xdocs/OMTutorial.html
Modified: webservices/commons/trunk/modules/axiom/xdocs/OMTutorial.html
URL:
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/xdocs/OMTutorial.html?rev=400372&r1=400371&r2=400372&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/xdocs/OMTutorial.html (original)
+++ webservices/commons/trunk/modules/axiom/xdocs/OMTutorial.html Sat May 6
14:28:09 2006
@@ -191,7 +191,7 @@
builder to create objects. The factory helps to keep the code at the
interface level and the implementations separately (Figure 2). Since OM is
tightly bound to StAX, a StAX compliant reader should be created first with
-the desired input stream. Then one can select one of the different builders
available.
+the desired input stream. Then one can select one of the different builders
available.
StAXOMBuilder will build pure XML infoset compliant object model whilst the
SOAPModelBuilder returns SOAP specific objects
(such as the SOAPEnvelope, which are sub classes of the OMElement) through
its builder methods and . The following piece of code shows the correct method
of
@@ -201,11 +201,11 @@
<p><b>Code Listing 1</b></p>
</div>
<source><pre>//create the parser<br/>
-XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(file));
+XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(file));
<br/>//create the builder<br/>
StAXOMBuilder builder = new StAXOMBuilder(parser);
//get the root element (in this case the envelope)<br/>
-OMElement documentElement = builder.getDocumentElement();
+OMElement documentElement = builder.getDocumentElement();
</pre>
</source>
<p>As the example shows, creating an OM from an input stream is pretty
@@ -352,12 +352,8 @@
elt1.addChild(elt2);
root.addChild(elt1);</pre>
-<p>Serilization of the root element produces the following XML</p>
-<pre class="xml"><x:root xmlns:x="bar" xmlns:y="bar1">
- <x:foo>
- <y:yuck>blah</y:yuck>
- </x:foo>
-</x:root></pre>
+<p>Serialization of the root element produces the following XML</p>
+<pre class="xml"><x:root xmlns:x="bar"
xmlns:y="bar1"><x:foo><y:yuck>blah</y:yuck></x:foo></x:root></pre>
<h3>Traversing</h3>
@@ -441,9 +437,9 @@
//dump the output to console with caching
envelope.serialize(writer);
writer.flush();</pre>
-
-or simply
-
+
+or simply
+
<pre class="code"> System.out.println(root.toStringWithConsume()); </pre>
<p>The above mentioned features of the serializer forces a correct
@@ -452,16 +448,10 @@
accurately figure out the namespaces. The example is from Code Listing 6
which creates a small OM programmatically. Serialization of the root element
produces the following,</p>
-<pre class="xml"><x:root xmlns:x="bar" xmlns:y="bar1">
- <x:foo>
- <y:yuck>blah</y:yuck>
- </x:foo>
-</x:root></pre>
+<pre class="xml"><x:root xmlns:x="bar"
xmlns:y="bar1"><x:foo><y:yuck>blah</y:yuck></x:foo></x:root></pre>
<p>However serialization of only the foo element produces the following</p>
-<pre class="xml"><x:foo xmlns:x="bar">
-<y:yuck xmlns:y="bar1">blah</y:yuck>
-</x:foo></pre>
+<pre class="xml"><x:foo xmlns:x="bar"><y:yuck
xmlns:y="bar1">blah</y:yuck></x:foo></pre>
<p>Note how the serializer puts the relevant namespace declarations in
place.</p>
@@ -476,9 +466,9 @@
<p><b>Code Listing 9</b></p>
</div>
<pre class="code">//create the parser
-XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(file));
+XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(file));
//create the builder
-StAXOMBuilder builder = new StAXOMBuilder(parser);
+StAXOMBuilder builder = new StAXOMBuilder(parser);
//get the root element (in this case the envelope)
OMElement documentElement = builder.getDocumentElement();
@@ -582,21 +572,13 @@
root.addChild(elt1);</pre>
<p>Serialization of the root element provides the following XML</p>
-<pre class="xml"><x:root xmlns:x="bar" xmlns:y="bar1">
-<x:foo>
- <y:yuck>blahblah</y:yuck>
- <y:yuck>blah</y:yuck>
-</x:foo>
-</x:root>
+<pre class="xml"><x:root xmlns:x="bar"
xmlns:y="bar1"><x:foo><y:yuck>blahblah</y:yuck><y:yuck>blah</y:yuck></x:foo></x:root>
</pre>
<p>However if the serialization is carried on the foo element then the
following XML is produced</p>
-<pre class="xml"><x:foo xmlns:x="bar" >
- <y:yuck " xmlns:y="bar1">blahblah</y:yuck>
- <y:yuck " xmlns:y="bar1">blah</y:yuck>
-</x:foo>
+<pre class="xml"><x:foo xmlns:x="bar" ><y:yuck
xmlns:y="bar1">blahblah</y:yuck><y:yuck
xmlns:y="bar1">blah</y:yuck></x:foo>
</pre>
@@ -623,7 +605,7 @@
import org.apache.axis2.impl.llom.factory.OMXMLBuilderFactory;
import javax.xml.stream.*;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class TestOMBuilder {
@@ -635,7 +617,7 @@
public static void main(String[] args) {
try {
//create the parser
- XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(args[0]));
+ XMLStreamReader parser =
XMLInputFactory.newInstance().createXMLStreamReader(new
FileInputStream(args[0]));
//get the root element (in this case the envelope)
OMElement documentElement = builder.getDocumentElement();