<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Implementazione parser]]></title><description><![CDATA[<p dir="auto">Salve a tutti,<br />
ho un (piccolo) problema: ho realizzato un browser in java e dovrei eseguire il parsing di file xml. Per il parsing utilizzo la classe SAXTreeViewer, ma non riesco a implementarla nel codice browser. Sapreste darmi una mano?<br />
grazie</p>
<p dir="auto">browser:</p>
<p dir="auto">class Webbrowser implements ActionListener<br />
{<br />
JTextField t1;<br />
JLabel l1;<br />
JButton b1;<br />
GridBagLayout gbl;<br />
GridBagConstraints gbc;<br />
JPanel p;<br />
JFrame frame;<br />
JScrollPane scrollPane;<br />
JEditorPane jep;<br />
static String initialPage;</p>
<p dir="auto">public Webbrowser()<br />
{<br />
<a href="//JFrame.setDefaultLookAndFeelDecorated" rel="nofollow ugc">//JFrame.setDefaultLookAndFeelDecorated</a>(true);<br />
/<em>try {<br />
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<br />
}<br />
catch(Exception e)<br />
{<br />
e.printStackTrace();<br />
}</em>/<br />
frame=new JFrame("Chicco's Web Browser");</p>
<p dir="auto">gbl=new GridBagLayout();<br />
gbc=new GridBagConstraints();</p>
<p dir="auto">p=new JPanel();<br />
p.setLayout(gbl);</p>
<p dir="auto">jep = new JEditorPane();</p>
<p dir="auto">t1=new JTextField();</p>
<p dir="auto">b1=new JButton("Trova");<br />
b1.addActionListener(this);<br />
frame.getRootPane().setDefaultButton(b1);</p>
<p dir="auto">l1=new JLabel("Indirizzo");</p>
<p dir="auto">gbc.anchor=GridBagConstraints.NORTHEAST;<br />
gbc.fill=GridBagConstraints.HORIZONTAL;<br />
gbc.gridx=0;<br />
gbc.gridy=0;<br />
gbc.weightx=0.0;<br />
gbl.setConstraints(l1,gbc);<br />
p.add(l1);</p>
<p dir="auto">gbc.anchor=GridBagConstraints.NORTHEAST;<br />
gbc.gridx=1;<br />
gbc.gridy=0;<br />
gbc.weightx=1.0;<br />
gbl.setConstraints(t1,gbc);<br />
p.add(t1);</p>
<p dir="auto">gbc.anchor=GridBagConstraints.NORTHWEST;<br />
gbc.gridx=2;<br />
gbc.gridy=0;<br />
gbc.weightx=0.0;<br />
gbl.setConstraints(b1,gbc);<br />
p.add(b1);</p>
<pre><code>scrollPane = new JScrollPane(jep);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(p,BorderLayout.NORTH);
</code></pre>
<p dir="auto">frame.getContentPane().add(scrollPane);<br />
frame.setSize(1000,700);<br />
frame.setVisible(true);<br />
}</p>
<p dir="auto">public void actionPerformed(ActionEvent e)<br />
{<br />
initialPage=t1.getText();<br />
char a=initialPage.charAt(0);<br />
char b=initialPage.charAt(1);<br />
char c=initialPage.charAt(2);<br />
char d=initialPage.charAt(3);<br />
char ea=initialPage.charAt(4);<br />
char f=initialPage.charAt(5);<br />
char g=initialPage.charAt(6);</p>
<p dir="auto">if((a=='h')&amp;&amp;(b=='t')&amp;&amp;(c=='t')&amp;&amp;(d=='p')&amp;&amp;(ea==':')&amp;&amp;(f=='/')&amp;&amp;(g=='/'))<br />
{<br />
initialPage=t1.getText();<br />
}<br />
else<br />
{<br />
initialPage="&lt;A href="http://"+initialPage"&gt;http://"+initialPage;<br />
}<br />
jep.setEditable(false);<br />
jep.addHyperlinkListener(new second(jep));<br />
try<br />
{<br />
jep.setPage(initialPage);<br />
}<br />
catch (IOException ae)<br />
{<br />
JOptionPane.showMessageDialog(frame,new String("Error: "+ae));<br />
}<br />
}</p>
<p dir="auto">public static void main(String[] args)<br />
{<br />
new Webbrowser();<br />
}<br />
}<br />
class second implements HyperlinkListener<br />
{<br />
private JEditorPane pane;</p>
<p dir="auto">public second(JEditorPane pane)<br />
{<br />
this.pane = pane;<br />
}<br />
public void hyperlinkUpdate(HyperlinkEvent evt)<br />
{<br />
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)<br />
{<br />
try<br />
{<br />
pane.setPage(evt.getURL());<br />
}<br />
catch (Exception e){}</p>
<p dir="auto">}}}<br />
public class browser extends javax.swing.JFrame {</p>
<pre><code>public browser() {
    initComponents();
    
}


// &lt;editor-fold defaultstate="collapsed" desc=" Generated Code "&gt;                          
private void initComponents() {
    menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    openMenuItem = new javax.swing.JMenuItem();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    editMenu = new javax.swing.JMenu();
    cutMenuItem = new javax.swing.JMenuItem();
    copyMenuItem = new javax.swing.JMenuItem();
    pasteMenuItem = new javax.swing.JMenuItem();
    deleteMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    contentsMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    fileMenu.setText("File");
    openMenuItem.setText("Open");
    fileMenu.add(openMenuItem);
    saveMenuItem.setText("Save");
    fileMenu.add(saveMenuItem);
    saveAsMenuItem.setText("Save As ...");
    fileMenu.add(saveAsMenuItem);
    exitMenuItem.setText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });
    fileMenu.add(exitMenuItem);
    menuBar.add(fileMenu);
    editMenu.setText("Edit");
    cutMenuItem.setText("Cut");
    editMenu.add(cutMenuItem);
    copyMenuItem.setText("Copy");
    editMenu.add(copyMenuItem);
    pasteMenuItem.setText("Paste");
    editMenu.add(pasteMenuItem);
    deleteMenuItem.setText("Delete");
    editMenu.add(deleteMenuItem);
    menuBar.add(editMenu);
    helpMenu.setText("Help");
    contentsMenuItem.setText("Contents");
    helpMenu.add(contentsMenuItem);
    aboutMenuItem.setText("About");
    helpMenu.add(aboutMenuItem);
    menuBar.add(helpMenu);
    setJMenuBar(menuBar);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 279, Short.MAX_VALUE)
    );
    pack();
}// &lt;/editor-fold&gt;                        


private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
    System.exit(0);
}                                            



    public static void main (String args[]) {
     java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new browser().setVisible(true);
            Webbrowser wb = new Webbrowser();             
        }
    }); 
}
    
// Variables declaration - do not modify                     
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JMenuItem contentsMenuItem;
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenu editMenu;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
// End of variables declaration                   
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Classe SAX:</p>
<p dir="auto">public class SAXTreeViewer extends JFrame {<br />
/** Default parser to use <em>/<br />
private String vendorParserClass =<br />
"org.apache.xerces.parsers.SAXParser";<br />
/</em>* The base tree to render <em>/<br />
private JTree jTree;<br />
/</em>* Tree model to use <em>/<br />
DefaultTreeModel defaultTreeModel;<br />
/</em>*<br />
* &lt;p&gt; This initializes the needed Swing settings. &lt;/p&gt;<br />
<em>/<br />
public SAXTreeViewer() {<br />
// Handle Swing setup<br />
super("SAX Tree Viewer");<br />
setSize(600, 450);<br />
}<br />
/</em>*<br />
* &lt;p&gt; This will construct the tree using Swing. &lt;/p&gt;<br />
*<br />
* @param filename &lt;code&gt;String&lt;/code&gt; path to XML document.<br />
*/<br />
public void init(String xmlURI) throws IOException, SAXException {<br />
DefaultMutableTreeNode base =<br />
new DefaultMutableTreeNode("XML Document: " +<br />
xmlURI);</p>
<pre><code>    // Build the tree model
    defaultTreeModel = new DefaultTreeModel(base);
    jTree = new JTree(defaultTreeModel);
    // Construct the tree hierarchy
    buildTree(defaultTreeModel, base, xmlURI);
    // Display the results
    getContentPane().add(new JScrollPane(jTree), 
        BorderLayout.CENTER);
}
/**
 * &lt;p&gt;This handles building the Swing UI tree.&lt;/p&gt;
 *
 * @param treeModel Swing component to build upon.
 * @param base tree node to build on.
 * @param xmlURI URI to build XML document from.
 * @throws &lt;code&gt;IOException&lt;/code&gt; - when reading the XML URI fails.
 * @throws &lt;code&gt;SAXException&lt;/code&gt; - when errors in parsing occur.
 */
public void buildTree(DefaultTreeModel treeModel, 
                      DefaultMutableTreeNode base, String xmlURI) 
    throws IOException, SAXException {
    // Create instances needed for parsing
    XMLReader reader = 
        XMLReaderFactory.createXMLReader(vendorParserClass);
    ContentHandler jTreeContentHandler = 
        new JTreeContentHandler(treeModel, base);
    ErrorHandler jTreeErrorHandler = new JTreeErrorHandler();
    // Register content handler
    reader.setContentHandler(jTreeContentHandler);
    // Register error handler
    reader.setErrorHandler(jTreeErrorHandler);
    // Parse
    InputSource inputSource = 
        new InputSource(xmlURI);
    reader.parse(inputSource);
}
/**
 * &lt;p&gt; Static entry point for running the viewer. &lt;/p&gt;
 */
public static void main(String[] args) {
    try {
        /*
         if (args.length != 1) {
            System.out.println(
                "Usage: java SAXTreeViewer " +
                "[XML Document URI]");
            System.exit(0);
        }*/
        SAXTreeViewer viewer = new SAXTreeViewer();
        //viewer.init(args[0]);
        viewer.init("[file.xml](http://www.freeitaly.it/gadget.xml)");
        viewer.setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>
<p dir="auto">}<br />
/**</p>
<ul>
<li>&lt;b&gt;&lt;code&gt;JTreeContentHandler&lt;/code&gt;&lt;/b&gt; implements the SAX</li>
<li>&lt;code&gt;ContentHandler&lt;/code&gt; interface and defines callback</li>
<li>behavior for the SAX callbacks associated with an XML</li>
<li>document's content, bulding up JTree nodes.<br />
<em>/<br />
class JTreeContentHandler implements ContentHandler {<br />
/</em>* Hold onto the locator for location information <em>/<br />
private Locator locator;<br />
/</em>* Store URI to prefix mappings <em>/<br />
private Map namespaceMappings;<br />
/</em>* Tree Model to add nodes to <em>/<br />
private DefaultTreeModel treeModel;<br />
/</em>* Current node to add sub-nodes to <em>/<br />
private DefaultMutableTreeNode current;<br />
/</em>*
<ul>
<li>&lt;p&gt; Set up for working with the JTree. &lt;/p&gt;</li>
<li></li>
<li>@param treeModel tree to add nodes to.</li>
<li>@param base node to start adding sub-nodes to.<br />
<em>/<br />
public JTreeContentHandler(DefaultTreeModel treeModel,<br />
DefaultMutableTreeNode base) {<br />
this.treeModel = treeModel;<br />
this.current = base;<br />
this.namespaceMappings = new HashMap();<br />
}<br />
/</em>*</li>
<li>&lt;p&gt;</li>
<li>Provide reference to &lt;code&gt;Locator&lt;/code&gt; which provides</li>
<li>information about where in a document callbacks occur.</li>
<li>&lt;/p&gt;</li>
<li></li>
<li>@param locator &lt;code&gt;Locator&lt;/code&gt; object tied to callback</li>
<li>
<pre><code>   process
</code></pre>
</li>
</ul>
<em>/<br />
public void setDocumentLocator(Locator locator) {<br />
// Save this for later use<br />
this.locator = locator;<br />
}<br />
/</em>*
<ul>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This indicates the start of a Document parse-this precedes</p>
</li>
<li>
<p dir="auto">all callbacks in all SAX Handlers with the sole exception</p>
</li>
<li>
<p dir="auto">of &lt;code&gt;{<a class="plugin-mentions-user plugin-mentions-a" href="/user/link" aria-label="Profile: link">@<bdi>link</bdi></a> <a href="/hashtags/setdocumentlocator">#setDocumentLocator</a>}&lt;/code&gt;.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void startDocument() throws SAXException {<br />
// No visual events occur here<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This indicates the end of a Document parse-this occurs after</p>
</li>
<li>
<p dir="auto">all callbacks in all SAX Handlers.&lt;/code&gt;.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void endDocument() throws SAXException {<br />
// No visual events occur here<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This indicates that a processing instruction (other than</p>
</li>
<li>
<pre><code>the XML declaration) has been encountered.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param target &lt;code&gt;String&lt;/code&gt; target of PI</p>
</li>
<li>
<p dir="auto">@param data &lt;code&gt;String&lt;/code containing all data sent to the PI.</p>
</li>
<li>
<pre><code>          This typically looks like one or more attribute value
</code></pre>
</li>
<li>
<pre><code>          pairs.
</code></pre>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void processingInstruction(String target, String data)<br />
throws SAXException {<br />
DefaultMutableTreeNode pi =<br />
new DefaultMutableTreeNode("PI (target = '" + target +<br />
"', data = '" + data + "')");<br />
current.add(pi);<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This indicates the beginning of an XML Namespace prefix</p>
</li>
<li>
<pre><code>mapping. Although this typically occurs within the root element
</code></pre>
</li>
<li>
<pre><code>of an XML document, it can occur at any point within the
</code></pre>
</li>
<li>
<pre><code>document. Note that a prefix mapping on an element triggers
</code></pre>
</li>
<li>
<pre><code>this callback &lt;i&gt;before&lt;/i&gt; the callback for the actual element
</code></pre>
</li>
<li>
<pre><code>itself (&lt;code&gt;{@link #startElement}&lt;/code&gt;) occurs.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param prefix &lt;code&gt;String&lt;/code&gt; prefix used for the namespace</p>
</li>
<li>
<pre><code>           being reported
</code></pre>
</li>
<li>
<p dir="auto">@param uri &lt;code&gt;String&lt;/code&gt; URI for the namespace</p>
</li>
<li>
<pre><code>          being reported
</code></pre>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void startPrefixMapping(String prefix, String uri) {<br />
// No visual events occur here.<br />
namespaceMappings.put(uri, prefix);<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This indicates the end of a prefix mapping, when the namespace</p>
</li>
<li>
<pre><code>reported in a &lt;code&gt;{@link #startPrefixMapping}&lt;/code&gt; callback
</code></pre>
</li>
<li>
<pre><code>is no longer available.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param prefix &lt;code&gt;String&lt;/code&gt; of namespace being reported</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void endPrefixMapping(String prefix) {<br />
// No visual events occur here.<br />
for (Iterator i = namespaceMappings.keySet().iterator();<br />
i.hasNext(); ) {<br />
String uri = (String)i.next();<br />
String thisPrefix = (String)namespaceMappings.get(uri);<br />
if (prefix.equals(thisPrefix)) {<br />
namespaceMappings.remove(uri);<br />
break;<br />
}<br />
}<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This reports the occurrence of an actual element. It includes</p>
</li>
<li>
<pre><code>the element's attributes, with the exception of XML vocabulary
</code></pre>
</li>
<li>
<pre><code>specific attributes, such as
</code></pre>
</li>
<li>
<pre><code>&lt;code&gt;xmlns:[namespace prefix]&lt;/code&gt; and
</code></pre>
</li>
<li>
<pre><code>&lt;code&gt;xsi:schemaLocation&lt;/code&gt;.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param namespaceURI &lt;code&gt;String&lt;/code&gt; namespace URI this element</p>
</li>
<li>
<pre><code>          is associated with, or an empty &lt;code&gt;String&lt;/code&gt;
</code></pre>
</li>
<li>
<p dir="auto">@param localName &lt;code&gt;String&lt;/code&gt; name of element (with no</p>
</li>
<li>
<pre><code>          namespace prefix, if one is present)
</code></pre>
</li>
<li>
<p dir="auto">@param qName &lt;code&gt;String&lt;/code&gt; XML 1.0 version of element name:</p>
</li>
<li>
<pre><code>           [namespace prefix]:[localName]
</code></pre>
</li>
<li>
<p dir="auto">@param atts &lt;code&gt;Attributes&lt;/code&gt; list for this element</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void startElement(String namespaceURI, String localName,<br />
String qName, Attributes atts)<br />
throws SAXException {<br />
DefaultMutableTreeNode element =<br />
new DefaultMutableTreeNode("Element: " + localName);<br />
current.add(element);<br />
current = element;<br />
// Determine namespace<br />
if (namespaceURI.length() &gt; 0) {<br />
String prefix =<br />
(String)namespaceMappings.get(namespaceURI);<br />
if (prefix.equals("")) {<br />
prefix = "[None]";<br />
}<br />
DefaultMutableTreeNode namespace =<br />
new DefaultMutableTreeNode("Namespace: prefix = '" +<br />
prefix + "', URI = '" + namespaceURI + "'");<br />
current.add(namespace);<br />
}<br />
// Process attributes<br />
for (int i=0; i&lt;atts.getLength(); i++) {<br />
DefaultMutableTreeNode attribute =<br />
new DefaultMutableTreeNode("Attribute (name = '" +<br />
atts.getLocalName(i) +<br />
"', value = '" +<br />
atts.getValue(i) + "')");<br />
String attURI = atts.getURI(i);<br />
if (attURI.length() &gt; 0) {<br />
String attPrefix =<br />
(String)namespaceMappings.get(namespaceURI);<br />
if (attPrefix.equals("")) {<br />
attPrefix = "[None]";<br />
}<br />
DefaultMutableTreeNode attNamespace =<br />
new DefaultMutableTreeNode("Namespace: prefix = '" +<br />
attPrefix + "', URI = '" + attURI + "'");<br />
attribute.add(attNamespace);<br />
}<br />
current.add(attribute);<br />
}<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">Indicates the end of an element</p>
</li>
<li>
<pre><code>(&lt;code&gt;&amp;lt;/[element name]&amp;gt;&lt;/code&gt;) is reached. Note that
</code></pre>
</li>
<li>
<pre><code>the parser does not distinguish between empty
</code></pre>
</li>
<li>
<pre><code>elements and non-empty elements, so this occurs uniformly.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param namespaceURI &lt;code&gt;String&lt;/code&gt; URI of namespace this</p>
</li>
<li>
<pre><code>           element is associated with
</code></pre>
</li>
<li>
<p dir="auto">@param localName &lt;code&gt;String&lt;/code&gt; name of element without prefix</p>
</li>
<li>
<p dir="auto">@param qName &lt;code&gt;String&lt;/code&gt; name of element in XML 1.0 form</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void endElement(String namespaceURI, String localName,<br />
String qName)<br />
throws SAXException {<br />
// Walk back up the tree<br />
current = (DefaultMutableTreeNode)current.getParent();<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This reports character data (within an element).</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param ch &lt;code&gt;char[]&lt;/code&gt; character array with character data</p>
</li>
<li>
<p dir="auto">@param start &lt;code&gt;int&lt;/code&gt; index in array where data starts.</p>
</li>
<li>
<p dir="auto">@param length &lt;code&gt;int&lt;/code&gt; index in array where data ends.</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void characters(char[] ch, int start, int length)<br />
throws SAXException {<br />
String s = new String(ch, start, length);<br />
DefaultMutableTreeNode data =<br />
new DefaultMutableTreeNode("Character Data: '" + s + "'");<br />
current.add(data);<br />
}<br />
/</em>*</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This reports whitespace that can be ignored in the</p>
</li>
<li>
<p dir="auto">originating document. This is typically invoked only when</p>
</li>
<li>
<p dir="auto">validation is ocurring in the parsing process.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param ch &lt;code&gt;char[]&lt;/code&gt; character array with character data</p>
</li>
<li>
<p dir="auto">@param start &lt;code&gt;int&lt;/code&gt; index in array where data starts.</p>
</li>
<li>
<p dir="auto">@param end &lt;code&gt;int&lt;/code&gt; index in array where data ends.</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
*/<br />
public void ignorableWhitespace(char[] ch, int start, int length)<br />
throws SAXException {</p>
<p dir="auto">// This is ignorable, so don't display it<br />
}<br />
/**</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This reports an entity that is skipped by the parser. This</p>
</li>
<li>
<pre><code>should only occur for non-validating parsers, and then is still
</code></pre>
</li>
<li>
<pre><code>implementation-dependent behavior.
</code></pre>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param name &lt;code&gt;String&lt;/code&gt; name of entity being skipped</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
<em>/<br />
public void skippedEntity(String name) throws SAXException {<br />
DefaultMutableTreeNode skipped =<br />
new DefaultMutableTreeNode("Skipped Entity: '" + name + "'");<br />
current.add(skipped);<br />
}<br />
}<br />
/</em>*</p>
</li>
</ul>
</li>
<li>&lt;b&gt;&lt;code&gt;JTreeErrorHandler&lt;/code&gt;&lt;/b&gt; implements the SAX</li>
<li>&lt;code&gt;ErrorHandler&lt;/code&gt; interface and defines callback</li>
<li>behavior for the SAX callbacks associated with an XML</li>
<li>document's warnings and errors.<br />
<em>/<br />
class JTreeErrorHandler implements ErrorHandler {<br />
/</em>*
<ul>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This will report a warning that has occurred; this indicates</p>
</li>
<li>
<p dir="auto">that while no XML rules were "broken", something appears</p>
</li>
<li>
<p dir="auto">to be incorrect or missing.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param exception &lt;code&gt;SAXParseException&lt;/code&gt; that occurred.</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
*/<br />
public void warning(SAXParseException exception)<br />
throws SAXException {</p>
<p dir="auto">System.out.println("<strong>Parsing Warning</strong>\n" +<br />
"  Line:    " +<br />
exception.getLineNumber() + "\n" +<br />
"  URI:     " +<br />
exception.getSystemId() + "\n" +<br />
"  Message: " +<br />
exception.getMessage());<br />
throw new SAXException("Warning encountered");<br />
}<br />
/**</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This will report an error that has occurred; this indicates</p>
</li>
<li>
<p dir="auto">that a rule was broken, typically in validation, but that</p>
</li>
<li>
<p dir="auto">parsing can reasonably continue.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param exception &lt;code&gt;SAXParseException&lt;/code&gt; that occurred.</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
*/<br />
public void error(SAXParseException exception)<br />
throws SAXException {</p>
<p dir="auto">System.out.println("<strong>Parsing Error</strong>\n" +<br />
"  Line:    " +<br />
exception.getLineNumber() + "\n" +<br />
"  URI:     " +<br />
exception.getSystemId() + "\n" +<br />
"  Message: " +<br />
exception.getMessage());<br />
throw new SAXException("Error encountered");<br />
}<br />
/**</p>
</li>
<li>
<p dir="auto">&lt;p&gt;</p>
</li>
<li>
<p dir="auto">This will report a fatal error that has occurred; this indicates</p>
</li>
<li>
<p dir="auto">that a rule has been broken that makes continued parsing either</p>
</li>
<li>
<p dir="auto">impossible or an almost certain waste of time.</p>
</li>
<li>
<p dir="auto">&lt;/p&gt;</p>
</li>
<li></li>
<li>
<p dir="auto">@param exception &lt;code&gt;SAXParseException&lt;/code&gt; that occurred.</p>
</li>
<li>
<p dir="auto">@throws &lt;code&gt;SAXException&lt;/code&gt; when things go wrong<br />
*/<br />
public void fatalError(SAXParseException exception)<br />
throws SAXException {</p>
<p dir="auto">System.out.println("<strong>Parsing Fatal Error</strong>\n" +<br />
"  Line:    " +<br />
exception.getLineNumber() + "\n" +<br />
"  URI:     " +<br />
exception.getSystemId() + "\n" +<br />
"  Message: " +<br />
exception.getMessage());<br />
throw new SAXException("Fatal Error encountered");<br />
}<br />
}</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Dove colloco SAXTreeViewer nel browser?</p>
]]></description><link>https://dev.connect.gt/topic/42015/implementazione-parser</link><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 02:00:20 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/42015.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Aug 2007 16:06:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Implementazione parser on Thu, 02 Aug 2007 03:19:39 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">Sapreste darmi una mano?<br />
...<br />
Dove colloco SAXTreeViewer nel browser?</p>
</blockquote>
<p dir="auto">Nessuno ti rispondera' in quest'area <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">Qui e' solo per le <strong>presentazioni</strong>.</p>
<p dir="auto">Leggiti meglio i messaggi che hai ricevuto al momento dell'iscrizione e consulta le Regole del forum prima di postare di nuovo. <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/54a3bffb-5e4a-4eb8-81dc-99b2072e5d05-175.gif?v=2190ae3dadd" class="not-responsive emoji emoji-customizations emoji--ciauz" style="height:1.4em;width:auto;vertical-align:middle" title=":ciauz:" alt="" /></p>
]]></description><link>https://dev.connect.gt/post/573730</link><guid isPermaLink="true">https://dev.connect.gt/post/573730</guid><dc:creator><![CDATA[andrez]]></dc:creator><pubDate>Thu, 02 Aug 2007 03:19:39 GMT</pubDate></item></channel></rss>