Xerces Xml Parser Java Example
Best Java code snippets using org.apache.xerces.parsers.DOMParser.parse (Showing top 20 results out of 378)
String xml = "<message>HELLO!</message>" ; DOMParser parser = new DOMParser(); try { parser. parse ( new InputSource( new java.io.StringReader(xml))); Document doc = parser.getDocument(); String message = doc.getDocumentElement().getTextContent(); System.out.println(message); } catch (SAXException e) { } catch (IOException e) { }
DOMParser parser = new DOMParser(); parser. parse ( "file:C:/temp/abc" );
import org.apache.xerces.parsers.DOMParser; import java.io.File; import org.w3c.dom.Document; public class SchemaTest { public static void main (String args[]) { File docFile = new File( "memory.xml" ); try { DOMParser parser = new DOMParser(); parser.setFeature( "http://xml.org/sax/features/validation" , true ); parser.setProperty( "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation" , "memory.xsd" ); ErrorChecker errors = new ErrorChecker(); parser.setErrorHandler(errors); parser. parse ( "memory.xml" ); } catch (Exception e) { System.out.print( "Problem parsing the file." ); } } }
public static void validate( String docStr, String schemaLocationPropertyValue, EntityResolver resolver) throws IOException, SAXException { if (resolver == null) { resolver = new Resolver(); } DOMParser parser = getParser(schemaLocationPropertyValue, resolver, true ); try { parser. parse ( new InputSource( new StringReader(docStr))); checkForParseError(parser); } catch (SAXParseException ex) { checkForParseError(parser, ex); } }
public static Document parse(InputStream in) throws SAXException, IOException { InputSource source = new InputSource(in); DOMParser parser = XmlUtil.getParser(null, null, false ); try { parser. parse (source); checkForParseError(parser); } catch (SAXParseException ex) { checkForParseError(parser, ex); } Document document = parser.getDocument(); return document; }
DOMParser parser= new DOMParser(); InputSource source= new InputSource(<the XML file/network stream>); parser. parse (source); Element docElement=parser.getDocument().getDocumentElement(); XPath xPath=xPathFactory.newXPath(); XPathExpression expression_=xPath.compile( "//case" ); NodeList list_=(NodeList)expression_.evaluate(docElement,XPathConstants.NODESET);DocumentBuilder documentBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document newDocument=documentBuilder.newDocument(); Element newElement=newDocument.createElement( "SOME_NAME" ); newDocument.appendChild(newElement); for ( int i= 0 ;i<list_.getLength();i++){Node n=newDocument.importNode(list_.item(i), true );newElement.appendChild(n);}
String s = "<position lat=\"59.3252414125\" long=\"18.0750236375\" accuracy=\"1000\"></position>" ; InputSource is = new InputSource( new StringReader(s)); DOMParser dp = new DOMParser(); dp. parse (is); Document doc = dp.getDocument(); NodeList nl = doc.getElementsByTagName( "position" ); Node n = nl.item( 0 ); NamedNodeMap nnm = n.getAttributes(); String lat = nnm.getNamedItem( "lat" ).getFirstChild().getTextContent(); String longg = nnm.getNamedItem( "long" ).getFirstChild().getTextContent(); String accuracy = nnm.getNamedItem( "accuracy" ).getFirstChild().getTextContent();
public EpsXmlParser(String xmlAnswer) { DOMParser parser = new DOMParser(); try { InputSource is = new InputSource(); is.setCharacterStream( new StringReader(xmlAnswer)); parser. parse (is); } catch (Exception e) { throw new RuntimeException( "Error on parsing document" , e); } Document doc = parser.getDocument(); parseXmlDoc(doc.getDocumentElement()); }
String nameFile= "<message>HELLO World</message>" ; DOMParser parser = new DOMParser(); try { parser. parse ( new InputSource( new java.io.StringReader(nameFile))); Document doc = parser.getDocument(); String message = doc.getDocumentElement().getTextContent(); System.out.println(message); } catch (SAXException e) { } catch (IOException e) { }
String xml = "<name>xyz</name>" ; DOMParser parser = new DOMParser(); try { parser. parse ( new InputSource( new java.io.StringReader(xml))); Document doc = parser.getDocument(); String message = doc.getDocumentElement().getTextContent(); System.out.println(message); } catch (Exception e) { }
@Override public Form loadFormFromXML(String xml) throws Exception { if (StringUtils.isBlank(xml)) { return null; } DOMParser parser = new DOMParser(); parser. parse ( new InputSource( new StringReader(xml))); Document doc = parser.getDocument(); NodeList nodes = doc.getElementsByTagName(NODE_FORM); Node rootNode = nodes.item( 0 ); return deserializeForm(rootNode); }
public void deserializeDataProperties(DataSet dataSet) throws Exception { if (StringUtils.isBlank(dataPropertiesXML)) return ; DOMParser parser = new DOMParser(); parser. parse ( new InputSource( new StringReader(dataPropertiesXML))); Document doc = parser.getDocument(); NodeList nodes = doc.getElementsByTagName( "dataproperty" ); dataSet.parseXMLProperties(nodes); }
public static synchronized Document getDocument(InputStream in, ErrorHandler handler) throws IOException, SAXException { parser.setErrorHandler(handler); InputSource source = new InputSource(in); parser. parse (source); return parser.getDocument(); }
import org.cyberneko.html.parsers.DOMParser; import org.w3c.dom.Document; ... public Document parseHtml(InputStream is) throws Exception { DOMParser parser = new DOMParser(); parser. parse ( new InputSource(is)); return parser.getDocument(); }
@Override public void loadURI(String uri) { try { domParser. parse ( new InputSource(uri)); document = domParser.getDocument(); } catch (SAXException e) { throw new ParseException(format( "SAXException while parsing HTML from \"%s\"." , uri), e); } catch (IOException e) { throw new ParseException(format( "SAXException while parsing HTML from \"%s\"." , uri), e); } }
public static String getStructure(String program) throws Exception { DOMParser parser = new DOMParser(); parser. parse ( new InputSource( new java.io.StringBufferInputStream(program))); Document doc = parser.getDocument(); NodeList nl = doc.getElementsByTagName( "program" ); if (nl.getLength() == 0 ) { throw new RuntimeException( "There is no <program> tag" ); } Node programNode = nl.item( 0 ); return getNodes( 0 , programNode); }
Document parse(Reader reader) throws ImportExportException { try { parser. parse ( new InputSource(reader)); } catch (SAXException ex) { throw new ImportExportException(ex); } catch (IOException ex) { throw new ImportExportException(ex); } Document dom = parser.getDocument(); injectCollectedStyles(dom); return dom; }
private void createFromInputStream(InputStream is) throws KlabIOException { parser = new DOMParser(); try { parser.setFeature( "http://xml.org/sax/features/namespaces" , true ); parser. parse ( new InputSource(is)); } catch (Exception e) { throw new KlabIOException(e); } dom = parser.getDocument(); }
public XMLDocument(InputStream is) throws KlabException { parser = new DOMParser(); try { parser.setFeature( "http://xml.org/sax/features/namespaces" , true ); parser. parse ( new InputSource(is)); } catch (Exception e) { throw new KlabValidationException(e); } dom = parser.getDocument(); }
public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception { DOMParser xmlReader = this .munitDomParser; xmlReader.setFeature( "http://xml.org/sax/features/validation" , Boolean.TRUE); xmlReader.setFeature( "http://xml.org/sax/features/namespaces" , Boolean.TRUE); xmlReader.setFeature( "http://apache.org/xml/features/validation/schema" , Boolean.TRUE); xmlReader.setFeature( "http://apache.org/xml/features/xinclude" , Boolean.FALSE); xmlReader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); xmlReader.setEntityResolver(entityResolver); xmlReader.setErrorHandler(errorHandler); xmlReader. parse (inputSource); return xmlReader.getDocument(); }
Source: https://www.tabnine.com/code/java/methods/org.apache.xerces.parsers.DOMParser/parse
0 Response to "Xerces Xml Parser Java Example"
Post a Comment