Parsing XML file containing HTML entities in Java without changing the XML

I would use a library like Jsoup for this purpose. I tested the following below and it works. I don’t know if this helps. It can be located here: http://jsoup.org/download public static void main(String args[]){ String html = “<?xml version=\”1.0\” encoding=\”UTF-8\”?><foo>” + “<bar>Some&nbsp;text &mdash; invalid!</bar></foo>”; Document doc = Jsoup.parse(html, “”, Parser.xmlParser()); for (Element e : … Read more

White spaces are required between publicId and systemId

The error message is actually correct if not obvious. It says that your DOCTYPE must have a SYSTEM identifier. I assume yours only has a public identifier. You’ll get the error with (for instance): <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”> You won’t with: <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd” “”> Notice “” at the end in the second one … Read more

Unable to read xml with namespace prefix using DOM parser

The W3C dom method for namespaced elements: getElementsByTagNameNS NodeList getElementsByTagNameNS(String namespaceURI, String localName) Returns a NodeList of all the Elements with a given local name and namespace URI in document order. Parameters: namespaceURI – The namespace URI of the elements to match on. The special value “*” matches all namespaces. localName – The local name … Read more

How to retrieve xml data from Javascript [duplicate]

here is an example wich can put you in the right direction: var request = new XMLHttpRequest(); request.open(“GET”, “/path/demo.xml”, false); request.send(); var xml = request.responseXML; var users = xml.getElementsByTagName(“user”); for(var i = 0; i < users.length; i++) { var user = users[i]; var names = user.getElementsByTagName(“name”); for(var j = 0; j < names.length; j++) { … Read more

Where I can find a detailed comparison of Java XML frameworks? [closed]

As Blaise pointed out stick with the standards. But there are multiple standards created over the period to solve different problems/usecases. Which one to choose completely depends upon your requirement. I hope the below comparison can help you choose the right one. Now there are two things you have to choose. API and the implementations … Read more

How to create a XML object from String in Java?

If you can create a string xml you can easily transform it to the xml document object e.g. – String xmlString = “<?xml version=\”1.0\” encoding=\”utf-8\”?><a><b></b><c></c></a>”; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xmlString))); } catch (Exception e) { e.printStackTrace(); } You can use the document object … Read more

Apostrophe not preceded by \

these should both work according to http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling: <string name=”search_occurs”>\'{string}\’ occurs {times}</string> <string name=”search_occurs”>”‘{string}’ occurs {times}”</string>

How to use sed to extract substring

grep was born to extract things: grep -Po ‘name=”\K[^”]*’ test with your data: kent$ echo ‘<parameter name=”PortMappingEnabled” access=”readWrite” type=”xsd:boolean”></parameter> <parameter name=”PortMappingLeaseDuration” access=”readWrite” activeNotify=”canDeny” type=”xsd:unsignedInt”></parameter> <parameter name=”RemoteHost” access=”readWrite”></parameter> <parameter name=”ExternalPort” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”ExternalPortEndRange” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”InternalPort” access=”readWrite” type=”xsd:unsignedInt”></parameter> <parameter name=”PortMappingProtocol” access=”readWrite”></parameter> <parameter name=”InternalClient” access=”readWrite”></parameter> <parameter name=”PortMappingDescription” access=”readWrite”></parameter> ‘|grep -Po ‘name=”\K[^”]*’ PortMappingEnabled PortMappingLeaseDuration RemoteHost ExternalPort … Read more