org.w3c.dom.EntityReference Java Examples
The following examples show how to use
org.w3c.dom.EntityReference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TSTokenView.java From alpha-wallet-android with MIT License | 5 votes |
private String getHTMLContent(Node content) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < content.getChildNodes().getLength(); i++) { Node child = content.getChildNodes().item(i); switch (child.getNodeType()) { case ELEMENT_NODE: sb.append("<"); sb.append(child.getLocalName()); sb.append(htmlAttributes(child)); sb.append(">"); sb.append(getHTMLContent(child)); sb.append("</"); sb.append(child.getLocalName()); sb.append(">"); break; case Node.COMMENT_NODE: //no need to record comment nodes break; case Node.ENTITY_REFERENCE_NODE: //load in external content String entityRef = child.getTextContent(); EntityReference ref = (EntityReference) child; System.out.println(entityRef); break; default: if (child != null && child.getTextContent() != null) { String parsed = child.getTextContent().replace("\u2019", "’"); sb.append(parsed); } break; } } return sb.toString(); }
Example #2
Source File: XmlUtil.java From hottub with GNU General Public License v2.0 | 5 votes |
public static String getTextForNode(Node node) { StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else sb.append(s); } else return null; } return sb.toString(); }
Example #3
Source File: DomUtils.java From spring-analysis-note with MIT License | 5 votes |
/** * Extracts the text value from the given DOM element, ignoring XML comments. * <p>Appends all CharacterData nodes and EntityReference nodes into a single * String value, excluding Comment nodes. Only exposes actual user-specified * text, no default values of any kind. * @see CharacterData * @see EntityReference * @see Comment */ public static String getTextValue(Element valueEle) { Assert.notNull(valueEle, "Element must not be null"); StringBuilder sb = new StringBuilder(); NodeList nl = valueEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node item = nl.item(i); if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) { sb.append(item.getNodeValue()); } } return sb.toString(); }
Example #4
Source File: DOMPrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #5
Source File: CoreDocumentImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #6
Source File: CoreDocumentImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #7
Source File: DOMPrinter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #8
Source File: XmlUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static String getTextForNode(Node node) { StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else sb.append(s); } else return null; } return sb.toString(); }
Example #9
Source File: DOMPrinter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #10
Source File: CoreDocumentImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #11
Source File: CoreDocumentImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #12
Source File: DOM3TreeWalker.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * End processing of given node * * * @param node Node we just finished processing * * @throws org.xml.sax.SAXException */ protected void endNode(Node node) throws org.xml.sax.SAXException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE : break; case Node.DOCUMENT_TYPE_NODE : serializeDocType((DocumentType) node, false); break; case Node.ELEMENT_NODE : serializeElement((Element) node, false); break; case Node.CDATA_SECTION_NODE : break; case Node.ENTITY_REFERENCE_NODE : serializeEntityReference((EntityReference) node, false); break; default : } }
Example #13
Source File: DomUtils.java From java-technology-stack with MIT License | 5 votes |
/** * Extracts the text value from the given DOM element, ignoring XML comments. * <p>Appends all CharacterData nodes and EntityReference nodes into a single * String value, excluding Comment nodes. Only exposes actual user-specified * text, no default values of any kind. * @see CharacterData * @see EntityReference * @see Comment */ public static String getTextValue(Element valueEle) { Assert.notNull(valueEle, "Element must not be null"); StringBuilder sb = new StringBuilder(); NodeList nl = valueEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node item = nl.item(i); if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) { sb.append(item.getNodeValue()); } } return sb.toString(); }
Example #14
Source File: XmlUtil.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static String getTextForNode(Node node) { StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else sb.append(s); } else return null; } return sb.toString(); }
Example #15
Source File: DOMPrinter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #16
Source File: DOMPrinter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #17
Source File: Bug6354955.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void testEntityReference() { try { Document xmlDocument = createNewDocument(); EntityReference erefNode = xmlDocument.createEntityReference("entityref"); String outerXML = getOuterXML(erefNode); System.out.println("OuterXML of Comment Node is:" + outerXML); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception occured: " + e.getMessage()); } }
Example #18
Source File: DomWriter.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Write. * * @param node * the node */ protected void write(EntityReference node) { printWriter.print('&'); printWriter.print(node.getNodeName()); printWriter.print(';'); printWriter.flush(); }
Example #19
Source File: CoreDocumentImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #20
Source File: AbstractNodeTester.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Validate a single Node by delegating to node type specific methods. * @see #testAttribute(Attr) * @see #testCDATASection(CDATASection) * @see #testComment(Comment) * @see #testDocumentType(DocumentType) * @see #testElement(Element) * @see #testEntity(Entity) * @see #testEntityReference(EntityReference) * @see #testNotation(Notation) * @see #testProcessingInstruction(ProcessingInstruction) * @see #testText(Text) */ public void testNode(Node aNode, NodeTest forTest) throws NodeTestException { switch (aNode.getNodeType()) { case Node.ATTRIBUTE_NODE: // should not happen as attributes are not exposed by DOM traversal testAttribute((Attr)aNode); break; case Node.CDATA_SECTION_NODE: testCDATASection((CDATASection)aNode); break; case Node.COMMENT_NODE: testComment((Comment)aNode); break; case Node.DOCUMENT_TYPE_NODE: testDocumentType((DocumentType)aNode); break; case Node.ELEMENT_NODE: testElement((Element)aNode); break; case Node.ENTITY_NODE: testEntity((Entity)aNode); break; case Node.ENTITY_REFERENCE_NODE: testEntityReference((EntityReference)aNode); break; case Node.NOTATION_NODE: testNotation((Notation)aNode); break; case Node.PROCESSING_INSTRUCTION_NODE: testProcessingInstruction( (ProcessingInstruction) aNode); break; case Node.TEXT_NODE: testText((Text)aNode); break; default: throw new NodeTestException("No delegate method for Node type", aNode); } }
Example #21
Source File: test_AbstractNodeTester.java From xmlunit with Apache License 2.0 | 5 votes |
public void testEntityReference() { AbstractNodeTester t = new AbstractNodeTester() { }; EntityReference n = doc.createEntityReference("foo"); try { t.testNode(n, null); fail("expected exception"); } catch (NodeTestException ex) { assertSame(n, ex.getNode()); } }
Example #22
Source File: CoreDocumentImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #23
Source File: XmlUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static String getTextForNode(Node node) { StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else sb.append(s); } else return null; } return sb.toString(); }
Example #24
Source File: CoreDocumentImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #25
Source File: DOMPrinter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #26
Source File: HtmlElement.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void checkChildHierarchy(final Node childNode) throws DOMException { if (!((childNode instanceof Element) || (childNode instanceof Text) || (childNode instanceof Comment) || (childNode instanceof ProcessingInstruction) || (childNode instanceof CDATASection) || (childNode instanceof EntityReference))) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Element may not have a child of this type: " + childNode.getNodeType()); } super.checkChildHierarchy(childNode); }
Example #27
Source File: XmlUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static String getTextForNode(Node node) { StringBuilder sb = new StringBuilder(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else sb.append(s); } else return null; } return sb.toString(); }
Example #28
Source File: CoreDocumentImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Factory method; creates an EntityReference having this Document * as its OwnerDoc. * * @param name The name of the Entity we wish to refer to * * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where * nonstandard entities are not permitted. (HTML not yet * implemented.) */ public EntityReference createEntityReference(String name) throws DOMException { if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new EntityReferenceImpl(this, name); }
Example #29
Source File: DOM3TreeWalker.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Start processing given node * * @param node Node to process * * @throws org.xml.sax.SAXException */ protected void startNode(Node node) throws org.xml.sax.SAXException { if (node instanceof Locator) { Locator loc = (Locator) node; fLocator.setColumnNumber(loc.getColumnNumber()); fLocator.setLineNumber(loc.getLineNumber()); fLocator.setPublicId(loc.getPublicId()); fLocator.setSystemId(loc.getSystemId()); } else { fLocator.setColumnNumber(0); fLocator.setLineNumber(0); } switch (node.getNodeType()) { case Node.DOCUMENT_TYPE_NODE : serializeDocType((DocumentType) node, true); break; case Node.COMMENT_NODE : serializeComment((Comment) node); break; case Node.DOCUMENT_FRAGMENT_NODE : // Children are traversed break; case Node.DOCUMENT_NODE : break; case Node.ELEMENT_NODE : serializeElement((Element) node, true); break; case Node.PROCESSING_INSTRUCTION_NODE : serializePI((ProcessingInstruction) node); break; case Node.CDATA_SECTION_NODE : serializeCDATASection((CDATASection) node); break; case Node.TEXT_NODE : serializeText((Text) node); break; case Node.ENTITY_REFERENCE_NODE : serializeEntityReference((EntityReference) node, true); break; default : } }
Example #30
Source File: DOMPrinter.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected void visitReference(EntityReference entityReference) throws XMLStreamException { visitChildren(entityReference); }