DOM XML parser to parse XML file in java

Steps to read a XML file: 1. Create a Document with DocumentBuilder class. 2. Fetch the root element. 3. Process the child elements. 4. Process the attributes. Example: StudentTest.xml <?xml version="1.0"?> <class> <student rollno="1"> <firstname>Swati</firstname> <lastname>Aneja</lastname> <marks>80</marks> </student> <student rollno="2"> <firstname>Prabhjot</firstname> <lastname>Kaur</lastname> <marks>70</marks> </student> <student rollno="3"> <firstname>Nidhi</firstname> <lastname>Gupta</lastname> <marks>75</marks> </student> </class><?xml version="1.0"?> <class> <student rollno="1"> … Read more

Java dom xml parser

The DOM refers to Document Object Model. The DOM parses the XML file, creates the DOM objects and loads it into the memory in the tree structure. Note: DOM is simple and easy to use but it consume lots of memory and slow. Interfaces defined by DOM: The DOM defines several Java interfaces. Here are … Read more

Parse json in java

Let us discuss how to parse JSON objects using Java with the help of below example. Steps: 1. Include JSON jar in classpath. 2. Define JSON string. 3. Create JSON parser object 4. Parse JSON string using JSON parser. 5. Process the object. Example: JSONTest.java package com.w3schools.business;   import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import … Read more

How to use JSON object in java?

Let us discuss how to use JSON object in java with the help of below example. Steps: 1. Include JSON jar in classpath. 2. Create JSONObject object. 3. Add data to JSONObject. 3. Process the object. Example: JSONTest.java package com.w3schools.business; import net.sf.json.JSONObject; /** * This class show use JSON object in java. * @author w3schools … Read more

Access json object array

Syntax: objectName[index].propertyName or objectName[index][“propertyName”]objectName[index].propertyName or objectName[index][“propertyName”] Example: <!DOCTYPE html> <html> <body>   <h2>Access json object array.</h2>   <p id="testDemo"></p>   <script> var textString = ‘{"students":[‘ + ‘{"firstName":"Sandy","lastName":"Sethi" },’ + ‘{"firstName":"Roxy","lastName":"Malik" },’ + ‘{"firstName":"Sunil","lastName":"Antil" }]}’;   var obj = JSON.parse(textString); document.getElementById("testDemo").innerHTML = obj.students[0].firstName + " " + obj.students[0].lastName; </script>   </body> </html> ]}<!DOCTYPE html> <html> <body> … Read more

Create json object from string

We can use JSON.parse() or eval() function to create json object from string in javascript. Using JSON.parse() function: Syntax: var obj = JSON.parse(textString); Example: <!DOCTYPE html> <html> <body>   <h2>Create json object from string.</h2>   <p id="testDemo"></p>   <script> var textString = ‘{"students":[‘ + ‘{"firstName":"Sandy","lastName":"Sethi" },’ + ‘{"firstName":"Roxy","lastName":"Malik" },’ + ‘{"firstName":"Sunil","lastName":"Antil" }]}’;   var obj … Read more

JSON data types

JSON Syntax: JSON syntax is a subset of the JavaScript object notation syntax. JSON syntax has following rules: 1. Data is represented in name/value pairs. 2. Data is separated by commas. 3. Curly braces hold objects and each object name is followed by colon. 4. Square brackets hold arrays. JSON example: {"students":[ {"firstName":"Sandy", "lastName":"Sethi"}, {"firstName":"Roxy", … Read more

Privacy Policy

Privacy Policy for www.w3schools.blog If you require any more information or have any questions about our privacy policy, please feel free to contact us by email at [email protected]. At www.w3schools.com, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by www.w3schools.com … Read more

Jsoup get form parameters

Let us discuss how to get form parameters using Jsoup API with the help of below example. Follow the below steps: 1. Create a HTML file containing form with some input parameters. 2. Use parse(File in, String charsetName) method of Jsoup class which returns Document object after processing the file object. 3. Get form by … Read more

Jsoup get metadata from HTML

Let us discuss how to get metadata from HTML using Jsoup API with the help of below example. Follow the below steps: 1. Use connect(String url) method of Jsoup class which returns the connection of specified URL. 2. Use get() method of Connection class which returns Document object. 3. Get metadata (description and keywords) from … Read more