Posts

Showing posts with the label XML

java reading xml from http

import java.io.File; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class ReadXml { public static void main(String[] args) { try {          String path="http://theprogrammersfirst.blogspot.com/sitemap.xml";          DocumentBuilderFactory dbFactory              = DocumentBuilderFactory.newInstance();          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();          Document doc = dBuilder.parse(new URL(path).openStream());          doc.getDocumentElement().normalize();          System.out.println("Root element :"              + doc.getDocumentElement().ge...

Compare XML using Java

It is developed specially for the SOAP service xml  request and response where you can compare according to names and also you can Find the Difference in values.Refer Below code, Compare two xml files. By Using Difference method you can Get the Difference in values. It Also Comapres XML Bi-Directional.  package com.example.Test; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Difference; import org.custommonkey.xmlunit.XMLUnit; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.S...