本文整理汇总了Java中org.apache.xerces.parsers.DOMParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DOMParser.parse方法的具体用法?Java DOMParser.parse怎么用?Java DOMParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xerces.parsers.DOMParser
的用法示例。
在下文中一共展示了DOMParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public Node load(String xmlfile) {
Document doc = null;
try{
DOMParser parser = new DOMParser();
parser.reset();
parser.parse(xmlfile);
doc = parser.getDocument();
}
catch (IOException ioe)
{ioe.printStackTrace();}
catch (SAXException saxe)
{saxe.printStackTrace();}
return doc;
}
示例2: loadXMLFile
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* Loads an XML file from an InputStream.
* <br>
* Note: the source stream is closed internally
*
* @param configurationFileStream the source stream
* @return the loaded XML document
* @throws IOException
* @throws SAXException
*/
public static Document loadXMLFile( InputStream configurationFileStream ) throws IOException,
SAXException {
try {
DOMParser parser = new DOMParser();
// Required settings from the DomParser
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
parser.parse(new InputSource(configurationFileStream));
return parser.getDocument();
} finally {
IoUtils.closeStream(configurationFileStream);
}
}
示例3: loadDocument
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* load a XML Document as DOM representation
* @param file XML File to load
* @return DOM Object
* @throws SAXException
* @throws IOException
*/
public Document loadDocument(Resource file) throws SAXException, IOException {
DOMParser parser = new DOMParser();
InputStream in = null;
try {
in = file.getInputStream();
InputSource source = new InputSource(in);
parser.parse(source);
}
finally {
IOUtil.closeEL(in);
}
return parser.getDocument();
}
示例4: init
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
@Override
public void init(lucee.runtime.config.Config config,Resource searchDir,
LogAndSource log/* always null*/) throws SAXException, IOException, SearchException {
this.config=config;
this.searchDir=searchDir;
this.searchFile=searchDir.getRealResource("search.xml");
if(!searchFile.exists()) createSearchFile(searchFile);
DOMParser parser = new DOMParser();
InputStream is=null;
try {
is = IOUtil.toBufferedInputStream(searchFile.getInputStream());
InputSource source = new InputSource(is);
parser.parse(source);
}
finally {
IOUtil.closeEL(is);
}
doc = parser.getDocument();
readCollections(config);
}
示例5: parseXMLPage
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
private List<String> parseXMLPage(Page page) {
DOMParser parser = new DOMParser();
try {
parser.parse(new InputSource(new ByteArrayInputStream(page.getContent())));
} catch (SAXException | IOException e) {
throw new RuntimeException("Failed to parse search results.", e);
}
Document doc = parser.getDocument();
NodeList list = doc.getElementsByTagName("d:Url");
List<String> urls = new ArrayList<String>();
for (int j = 0; j < list.getLength(); j++) {
Node node = list.item(j);
NodeList children = node.getChildNodes();
Node child = children.item(0);
urls.add(child.getTextContent());
}
return urls;
}
示例6: parse
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* Parse a stream into a Document (no validation).
*
*/
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;
}
示例7: validate
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
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);
}
}
示例8: parseCase
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* Parses the XML into an instance of the domain class defined in the class parameter.
*
* @return the created instance
* @throws CaseParserException if there were problems while parsing case XML
*/
public T parseCase() throws CaseParserException {
DOMParser parser = new DOMParser();
InputSource inputSource = new InputSource();
inputSource.setCharacterStream(new StringReader(xmlDoc));
CaseXml ccCase;
try {
parser.parse(inputSource);
ccCase = parseCase(parser.getDocument());
} catch (IOException | SAXException ex) {
throw new CaseParserException(ex,
"Exception while trying to parse caseXml");
}
return domainMapper.mapToDomainObject(ccCase);
}
示例9: loadDocument
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public static Document loadDocument(URL fileUrl) {
Document doc = null;
DOMParser parser = new DOMParser();
if (logger.isDebugEnabled()) {
logger.debug("Loading document from " + fileUrl.toExternalForm());
}
try {
InputSource inputSource = new InputSource(fileUrl.openStream());
parser.parse(inputSource);
doc = parser.getDocument();
} catch (Exception e) {
logger.warn("Unable to load document: " + e.getMessage());
}
return doc;
}
示例10: getPackageManifestDOMDocument
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public Document getPackageManifestDOMDocument(IProject project) throws FactoryException {
IFile packageManifestFile = getPackageManifestFile(project);
Document document = null;
try {
InputSource content = new InputSource(packageManifestFile.getContents());
DOMParser parser = new DOMParser();
parser.parse(content);
document = parser.getDocument();
} catch (CoreException ce) {
String logMessage = Utils.generateCoreExceptionLog(ce);
logger.error("Core exception occurred when marshalling package manifest into DOM document: " + logMessage,
ce);
throw new FactoryException("Unable to create DOM document from path "
+ packageManifestFile.getProjectRelativePath().toPortableString(), ce);
} catch (SAXException se) {
logger.error("SAX exception occurred when marshalling package manifest into DOM document", se);
throw new FactoryException("Unable to create DOM document from path "
+ packageManifestFile.getProjectRelativePath().toPortableString(), se);
} catch (IOException ioe) {
logger.error("IO exception occurred when marshalling package manifest into DOM document", ioe);
throw new FactoryException("Unable to create DOM document from path "
+ packageManifestFile.getProjectRelativePath().toPortableString(), ioe);
}
return document;
}
示例11: parse
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
@Override
public Document parse() throws SAXException, IOException
{
//temporay NekoHTML fix until nekohtml gets fixed
if (!neko_fixed)
{
HTMLElements.Element li = HTMLElements.getElement(HTMLElements.LI);
HTMLElements.Element[] oldparents = li.parent;
li.parent = new HTMLElements.Element[oldparents.length + 1];
for (int i = 0; i < oldparents.length; i++)
li.parent[i] = oldparents[i];
li.parent[oldparents.length] = HTMLElements.getElement(HTMLElements.MENU);
neko_fixed = true;
}
DOMParser parser = new DOMParser(new HTMLConfiguration());
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
if (charset != null)
parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));
return parser.getDocument();
}
示例12: testBasicGroupBy
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* A simple test to verify that we can actually facet on a simple field and get back all values
* across all documents, this is the same as faceting in regular solr.
*
* @throws Exception
*/
@Test
public void testBasicGroupBy() throws Exception {
ModifiableSolrParams p = new ModifiableSolrParams();
p.set("q", "*:*");
p.set("wt", "xml");
p.set("rows", "0");
p.set("indent", "true");
p.set(GroupByComponent.Params.GROUPBY, "_root_");
SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), p);
String response = h.query(req);
System.out.println(response);
DOMParser parser = new DOMParser();
parser.parse(new InputSource(new StringReader(response)));
Document document = parser.getDocument();
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.compile("//lst[@name='group']//lst[@name='_root_']//lst//int[@name='count']").evaluate(document, XPathConstants.NODESET);
assertEquals(2, nodes.getLength());
assertEquals("6", nodes.item(0).getTextContent());
assertEquals("5", nodes.item(1).getTextContent());
}
示例13: parse
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public Document parse() throws SAXException, IOException
{
DOMParser parser = new DOMParser(new HTMLConfiguration());
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower");
if (charset != null)
parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
//preparation for filters, not used now
/*XMLDocumentFilter attributeFilter = new DOMAttributeFilter();
XMLDocumentFilter[] filters = { attributeFilter };
parser.setProperty("http://cyberneko.org/html/properties/filters", filters);*/
parser.parse(new org.xml.sax.InputSource(is));
doc = parser.getDocument();
return doc;
}
示例14: prepareResponse
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
protected void prepareResponse(String resource) throws Exception {
capabilitiesXml = IOUtils.toString(this.getClass().getResourceAsStream(resource), "UTF-8");
DOMParser parser = new DOMParser();
parser.parse(new InputSource(new StringReader(capabilitiesXml)));
capabilitiesDoc = w3cToGoogle(parser.getDocument());
final Response response = mock(Response.class);
when(response.getStatusCode()).thenReturn(200);
when(response.getText()).thenReturn(capabilitiesXml);
when(requestBuilder.sendRequest(anyString(), any(RequestCallback.class))).thenAnswer(new Answer<Request>() {
@Override
public Request answer(InvocationOnMock invocation) throws Throwable {
((RequestCallback) invocation.getArguments()[1]).onResponseReceived(null, response);
return null;
}
});
}
示例15: parseSiteXML
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public static void parseSiteXML(AddingPanelData data)
throws SAXException, IOException {
File XMLFile = new File(TemplateConstants.SITE_FILE);
if (XMLFile.exists()) {
DOMParser parser = new DOMParser();
InputSource in_source = new InputSource(TemplateConstants.SITE_FILE);
//TODO: the parser must be created first
parser.parse(in_source);
Document doc = parser.getDocument();
NodeList sites = doc.getElementsByTagName("site");
List<String> siteNames = data.getSiteNames();
List<String> siteURLs = data.getSiteURLs();
List<String> siteInfos = data.getSiteInfos();
// extract the repository info
for (int i = 0; i < sites.getLength(); i++) {
Element temp = (Element) sites.item(i);
String siteName = temp.getElementsByTagName("name").item(0)
.getTextContent();
String siteURL = temp.getElementsByTagName("URL").item(0)
.getTextContent();
// the info displayed in the bar
String siteInfo = siteName + " - " + siteURL;
siteNames.add(siteName);
siteURLs.add(siteURL);
siteInfos.add(siteInfo);
}
}
}