下面列出了org.w3c.dom.Document#setDocumentURI ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
public Option<Document> getDocumentFromFile(File file){
try {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
document.setDocumentURI(file.getAbsolutePath());
return Option.of(document);
} catch (Exception e) {
messageUtils.error(Option.<Element>absent(), e.getMessage());
return Option.absent();
}
}
/**
* Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
* before converting.
* @param in jsoup doc
* @param out w3c doc
* @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
*/
public void convert(org.jsoup.nodes.Document in, Document out) {
if (!StringUtil.isBlank(in.location()))
out.setDocumentURI(in.location());
org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
NodeTraversor traversor = new NodeTraversor(new W3CBuilder(out));
traversor.traverse(rootEl);
}
/**
* Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
* before converting.
* @param in jsoup doc
* @param out w3c doc
* @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
*/
public void convert(org.jsoup.nodes.Document in, Document out) {
if (!StringUtil.isBlank(in.location()))
out.setDocumentURI(in.location());
org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
/**
* Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
* before converting.
* @param in jsoup doc
* @param out w3c doc
* @see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
*/
public void convert(org.jsoup.nodes.Document in, Document out) {
if (!StringUtil.isBlank(in.location()))
out.setDocumentURI(in.location());
org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
public static Document copy(Document doc)
throws XMLStreamException, ParserConfigurationException {
XMLStreamReader reader = createXMLStreamReader(doc);
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
copy(reader, writer);
Document d = writer.getDocument();
try {
d.setDocumentURI(doc.getDocumentURI());
} catch (Exception ex) {
//ignore - probably not DOM level 3
}
return d;
}
public static Document read(XMLStreamReader reader, boolean recordLoc) throws XMLStreamException {
Document doc = DOMUtils.createDocument();
if (reader.getLocation().getSystemId() != null) {
try {
doc.setDocumentURI(reader.getLocation().getSystemId());
} catch (Exception e) {
//ignore - probably not DOM level 3
}
}
readDocElements(doc, doc, reader, true, recordLoc);
return doc;
}
public static Document read(DocumentBuilder builder, XMLStreamReader reader, boolean repairing)
throws XMLStreamException {
Document doc = builder == null ? DOMUtils.createDocument() : builder.newDocument();
if (reader.getLocation().getSystemId() != null) {
try {
doc.setDocumentURI(reader.getLocation().getSystemId());
} catch (Exception e) {
//ignore - probably not DOM level 3
}
}
readDocElements(doc, reader, repairing);
return doc;
}
/**
* Parses an XML Document from a classpath resource.
*
* @param resourcePath relative to the current class
* @return never null
*/
private Document parseResourceDocument(final String resourcePath)
throws SAXException, IOException {
final URL url = getClass().getResource(resourcePath);
final Document doc = docBuilder.parse(url.toString());
doc.setDocumentURI(url.toString());
return doc;
}