Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Plz help me using Java SAX -------- you can use Google chart tools? https://deve

ID: 657960 • Letter: P

Question

Plz help me using Java SAX --------you can use Google chart tools? https://developers.google.com/chart/interactive/docs/quick_start?csw=1 ?--------by processing the XML and  to create graphs like the one shown below...

Part of the charts.xml~~~


<?xml version="1.0"?>

<!DOCTYPE charts [
   <!ELEMENT charts (chart)>
   <!ELEMENT chart (title, columns+, rows+)>
   <!ELEMENT title (#PCDATA)>
   <!ELEMENT columns (column)+>
   <!ELEMENT column EMPTY>
   <!ELEMENT rows (row)+>
   <!ELEMENT row EMPTY>
  
   <!ATTLIST charts
           num_charts CDATA #IMPLIED
           chart_id ID #REQUIRED>
<!ATTLIST chart
           type CDATA #IMPLIED
           width CDATA #IMPLIED
           height CDATA #IMPLIED
           align CDATA #IMPLIED>
   <!ATTLIST column name (Topping|Slices) "Topping">
   <!ATTLIST column type (string|number) "string">
   <!ATTLIST row name (Mushrooms|Onions|Olives|Zucchini|Pepperoni) "Mushrooms">
   <!ATTLIST row value (3|1|2) "3">

]>


<charts num_charts="1" chart_id="chart_div">

<chart type="pie" width="400" height="300" align="left">
<title>How Much Pizza I Ate Last Night</title>
  
<columns>
<column name="Topping" type="string"/>
<column name="Slices" type="number"/>   
</columns>
  
<rows>
<row name="Mushrooms" value="3" />
<row name="Onions" value="1" />   
<row name="Olives" value="1" />
<row name="Zucchini" value="1" />
<row name="Pepperoni" value="2" />
</rows>
</chart>

</charts>

Visit Google's Charts Gallery " https://developers.google.com/chart/interactive/docs/gallery?csw=1 "

Explanation / Answer

import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class ValidateWithExternalDTD { private static final String URL = "http://127.0.0.1:8080/sample/charts.xml"; private static final String DTD = "http://127.0.0.1/YourDTD.dtd"; public static void main(String args[]) { try { DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); // Set the error handler builder.setErrorHandler(new org.xml.sax.ErrorHandler() { public void fatalError(SAXParseException spex) throws SAXException { // output error and exit spex.printStackTrace(); System.exit(0); } public void error(SAXParseException spex) throws SAXParseException { // output error and continue spex.printStackTrace(); } public void warning(SAXParseException spex) throws SAXParseException { // output warning and continue spex.printStackTrace(); } }); // Read the document URL url = new URL(ValidateWithExternalDTD.URL); Document xmlDocument = builder.parse(url.openStream()); DOMSource source = new DOMSource(xmlDocument); // Use the tranformer to validate the document StreamResult result = new StreamResult(System.out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, ValidateWithExternalDTD.DTD); transformer.transform(source, result); // Process your document if everything is OK } catch (Exception ex) { ex.printStackTrace(); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote