List of usage examples for java.io StringReader StringReader
public StringReader(String s)
From source file:Main.java
public static void checkWellformed(String out) throws Exception { synchronized (wellformedSet) { if (wellformedSet.contains(out)) { return; }/* w w w .ja v a 2 s . c om*/ } XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(out)); do { reader.next(); } while (reader.hasNext()); synchronized (wellformedSet) { wellformedSet.add(out); } }
From source file:Main.java
public static boolean validateXMLString(String xsdPath, String xml) { try {/*from ww w . j av a2 s . co m*/ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new File(xsdPath)); Validator validator = schema.newValidator(); Source source = new StreamSource(new StringReader(xml)); validator.validate(source); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
public static Document getStringToDocument(String xml) throws TransformerException, ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); return document; }
From source file:Main.java
public static String tranform(String xslSource, String original) { StringReader sr = new StringReader(xslSource); StringReader sro = new StringReader(original); StringWriter result = new StringWriter(); doTransform(new StreamSource(sr), new StreamSource(sro), new StreamResult(result)); return result.toString(); }
From source file:Main.java
public static String getRequestID(String xml) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); Node reqName = document.getElementsByTagName("request-id").item(0); if (reqName != null) return reqName.getTextContent(); else// ww w . j a va2 s . c o m return null; }
From source file:Main.java
public static String getUnicastID(String xml) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); Node reqName = document.getElementsByTagName("unicast-id").item(0); if (reqName != null) return reqName.getTextContent(); else/* w w w.jav a 2s.com*/ return null; }
From source file:Main.java
private static StringReader fromStreamToStringReader(InputStream inputStream, String encoding) { StringBuilder content = new StringBuilder(); Scanner scanner = null;//w w w . java2 s . co m try { scanner = new Scanner(inputStream, encoding); while (scanner.hasNextLine()) { content.append(scanner.nextLine()).append("\n"); } } finally { if (scanner != null) { scanner.close(); } } return new StringReader(content.toString()); }
From source file:Main.java
public static String getRequestName(String xml) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); Node reqName = document.getElementsByTagName("request-name").item(0); if (reqName != null) return reqName.getTextContent(); else// w ww .j a v a 2 s. c om return null; }
From source file:Main.java
/** * Extract a String node from an XML Message * * @param xpath XPath object//from w ww .j a v a 2 s. c o m * @param nodePath XPath statement to locate the node * @param xmlString Xml string object to extract the data from * @return The requested data, or "" if not found. */ public static String extractNode(XPath xpath, String nodePath, String xmlString) { InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return (String) xpath.evaluate(nodePath, inputSource, XPathConstants.STRING); } catch (XPathExpressionException e) { return ""; } }
From source file:Main.java
public static Document loadXMLFromString(String xml) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); }