Home » Core Java » xml » Page 5

xml

Modify XML File in Java using JDOM parser example

In the previous tutorial we show how to read an XML File using JDOM parser. In this tutorial we are going to see how to modify the contents of an XML File.                     This is the XML File we are going to use for the demonstration. testFile.xml: <?xml version="1.0" encoding="UTF-8" standalone="no"?><company> ...

Read More »

Read XML File in Java using JDOM parser example

In this example we are going to see how to parse an XML File using JDOM. JDOM is a Java representation of an XML. It’s a very easy to use tool and it has a straightforward API. It’s an alternative to DOM and SAX and it integrates equally well with both of them. JDOM is an external library and you ...

Read More »

Read UTF-8 XML File in Java using SAX parser example

In the previous SAX parser tutorial we saw how to parse and read a simple XML File. If your file had UTF-8 encoding, there is a chance that the client produced a MalformedByteSequenceException. In order to solve this you have to set the InputSource encoding to UTF-8.                 You can do this with ...

Read More »

Read XML File in Java using SAX parser example

In this tutorial we are going to see how you can parse an XML File using a SAX parser. SAX parsers are very popular and much more frequently used than DOM parsers. The reason is that they are much more memory efficient (and this is important for large XML Files) and much faster. It’s all down to the way the ...

Read More »

Count XML Elements in Java using DOM parser example

In this example we are going to see how to count elements with specific tag names using a DOM parser in Java. Basically all you have to do in order to count elements in an XML elements is: Open and parse an XML Document using a DocumentBuilder Use Document.getElementsByTagName that will return a list with nodes. Simply print out the ...

Read More »

Create XML File in Java using DOM parser example

In this tutorial we are going to see how to create XML File in Java using DOM parser. The basic idea is very simple. You construct the DOM object with the tree structure you want in the memory, and then you use a Transformer and a StreamResult in order to write the DOM object to a stream, in our case ...

Read More »

Modify XML File in Java using DOM parser example

With this tutorial we shall show you you can read and modify the contents of an XML File using a DOM parser. The basic idea is pretty straight forward. You read the XML File and use a DOM parser to parse it and construct the DOM object in the memory. Then you can just select any item you want from ...

Read More »

Read XML File in Java using DOM parser example

In this tutorial we are going to see how to use the built in Java DOM parser in order to parse an XML file into a DOM Object As you might know, the DOM object has the classic Tree Structure with nodes, elements, attributes etc… Remember that DOM parser reads the XML file and constructs the DOM object in the ...

Read More »

Find elements by id with XPath

With this example we are going to demonstrate how to find elements by Id using XPath. The XPath language provides a simple, concise syntax for selecting nodes from an XML document. XPath also provides rules for converting a node in an XML document object model (DOM) tree to a boolean, double, or string value. In short, to find elements by ...

Read More »

Find elements by content with XPath

This is an example of how to find elements by content using XPath. The XPath language provides a simple, concise syntax for selecting nodes from an XML document. XPath also provides rules for converting a node in an XML document object model (DOM) tree to a boolean, double, or string value. Finding elements by content using XPath implies that you ...

Read More »