Question : Java SAX

Hi there,

I have the following SAX java the parses an XML element and  prints output.

Can someone checks the output if it is correct or not ? I suspect it is in correct because there is no system.out.println it is print NOT println !!!

Please check
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:
***Output:

(quotes[
](quote[
](play[The Tempest])[
](character[MIRANDA])[
](act[I])[
](scene[The island. Before PROSPERO’S cell.])[
](quote_text[
The strangeness of your story put heaviness in me.
])[
])[
](quote[
](play[Love’s Labour’s Lost])[
](character[MOTH])[
](act[I])[
](scene[II])[
](quote_text[
I will praise an eel with the same praise.
])[
])[
])

***SAX JAVA

public void startElement(String namespaceURI, String name, String qname, Attributes attrs) {
System.out.print("(" + qname);
}
public void endElement(String namespaceURI, String name, String qname) {
System.out.print(")");
}
public void characters (char ch[], int start, int length) {
System.out.print("[");
for (int i = start; i < start + length; i++) {
System.out.print(ch[i]);
}
System.out.print("]");
}

**XML Source;

<quotes>
<quote>
<play>The Tempest</play>
<character>MIRANDA</character>
<act>I</act>
<scene>The island. Before PROSPERO’S cell.</scene>
<quote_text>
The strangeness of your story put heaviness in me.
</quote_text>
</quote>
<quote>
<play>Love’s Labour’s Lost</play>
<character>MOTH</character>
<act>I</act>
<scene>II</scene>
<quote_text>
I will praise an eel with the same praise.
</quote_text>
</quote>
</quotes>

Answer : Java SAX

Look at lines 8-11 of the output that you originally posted, and lines 47-50 are the corresponding lines from the input xml. Notice how line 8 doesn't have the new lines, that because line 47 doesn't have the new lines. And similarly, lines 9,10,11 are on separate lines because lines 48,49,50 are on separate lines. It isn't the code _inserting_ any new lines, it is just copying them from the input.
Random Solutions  
 
programming4us programming4us