switch (node.getNodeType()) String data = ((Comment) node).getData(); NamedNodeMap atts = elem_node.getAttributes(); int nAttrs = atts.getLength(); final Node attr = atts.item(i); final String attrName = attr.getNodeName(); final int colon = attrName.indexOf(':'); final String prefix; prefix = attrName.substring(colon + 1); this.m_contentHandler.startPrefixMapping(prefix, attr.getNodeValue()); String uri = attr.getNamespaceURI(); if (uri != null) this.m_contentHandler.startPrefixMapping(prefix,uri); String name = pi.getNodeName(); this.m_contentHandler.processingInstruction(pi.getNodeName(), pi.getData()); eref.getNodeName());
private void visit( Node n ) throws SAXException { setCurrentLocation( n ); // if a case statement gets too big, it should be made into a separate method. switch(n.getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String value = n.getNodeValue(); receiver.characters( value.toCharArray(), 0, value.length() ); break; case Node.ELEMENT_NODE: visit( (Element)n ); break; case Node.ENTITY_REFERENCE_NODE: receiver.skippedEntity(n.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; receiver.processingInstruction(pi.getTarget(),pi.getData()); break; } }
public final void setNodeValue(String nodeValue) throws DOMException { switch (getNodeType()) { case CDATA_SECTION_NODE: case COMMENT_NODE: case TEXT_NODE: ((CharacterData) this).setData(nodeValue); return; case PROCESSING_INSTRUCTION_NODE: ((ProcessingInstruction) this).setData(nodeValue); return; case ATTRIBUTE_NODE: ((Attr) this).setValue(nodeValue); return; case ELEMENT_NODE: case ENTITY_REFERENCE_NODE: case ENTITY_NODE: case DOCUMENT_NODE: case DOCUMENT_TYPE_NODE: case DOCUMENT_FRAGMENT_NODE: case NOTATION_NODE: return; // do nothing! default: throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unsupported node type " + getNodeType()); } }
/** * Loads the given processing instruction in the current sequence. * * @param pi The W3C DOM PI node to load. * * @throws LoadingException If thrown while parsing. */ private void load(ProcessingInstruction pi) throws LoadingException { this.sequence.addEvent(new ProcessingInstructionEvent(pi.getTarget(), pi.getData())); this.currentWeight++; }
/** * Serializes an ProcessingInstruction Node. * * @param node The ProcessingInstruction Node to serialize */ protected void serializePI(ProcessingInstruction node) throws SAXException { ProcessingInstruction pi = node; String name = pi.getNodeName(); // well-formed=true if ((fFeatures & WELLFORMED) != 0) { isPIWellFormed(node); } // apply the LSSerializer filter if (!applyFilter(node, NodeFilter.SHOW_PROCESSING_INSTRUCTION)) { return; } // String data = pi.getData(); if (name.equals("xslt-next-is-raw")) { fNextIsRaw = true; } else { this.fSerializer.processingInstruction(name, pi.getData()); } }
private static void print(Node node, String indent, String increment, StringBuilder stringBuilder) { if(node != null) { if(indent == null) indent = ""; switch(node.getNodeType()) { case Node.DOCUMENT_NODE: { Node child = node.getFirstChild(); while(child != null) { print(child, indent, increment, stringBuilder); child = child.getNextSibling(); stringBuilder.append(indent + "<" + ele.getTagName()); NamedNodeMap attrs = ele.getAttributes(); for(int i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); stringBuilder.append(" " + a.getNodeName() + "='" + escapeXML(a.getNodeValue()) + "'"); Node child = ele.getFirstChild(); while(child != null) { print(child, indent + increment, increment, stringBuilder); stringBuilder.append(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>\n"); break; stringBuilder.append(indent + "<!--" + c.getData() + "-->\n"); break;
return; switch (node.getNodeType()) { case Node.DOCUMENT_NODE: startDocument((Document) node); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) printNode(child); endDocument(); Element elt = (Element) node; startElement(elt.getNamespaceURI(), elt.getLocalName(), elt.getNodeName()); NamedNodeMap attrs = elt.getAttributes(); int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); comment(comment.getData()); break; processingInstruction(pi.getNodeName(), pi.getData()); break;
final Document doc = parent.getOwnerDocument(); switch (child.getNodeType()) { case Node.CDATA_SECTION_NODE: copy = doc.createCDATASection(((CDATASection) child).getData()); break; case Node.COMMENT_NODE: copy = doc.createComment(((Comment) child).getData()); break; case Node.DOCUMENT_FRAGMENT_NODE: break; case Node.ELEMENT_NODE: final Element elem = doc.createElement(((Element) child).getTagName()); copy = elem; final NamedNodeMap attributes = child.getAttributes(); if (attributes != null) { final int size = attributes.getLength(); for (int i = 0; i < size; i++) { final Attr attr = (Attr) attributes.item(i); elem.setAttribute(attr.getName(), attr.getValue()); case Node.PROCESSING_INSTRUCTION_NODE: final ProcessingInstruction pi = (ProcessingInstruction) child; copy = doc.createProcessingInstruction(pi.getTarget(), pi.getData()); break; case Node.TEXT_NODE:
int nodeLength = 0; int textLength = 0; if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) { nextIndex = xmlString.indexOf("<!DOCTYPE", nextIndex); } else if (n.getNodeType() == Node.COMMENT_NODE) { nextIndex = xmlString.indexOf("<!--", nextIndex); } else if (n.getNodeType() == Node.ELEMENT_NODE) { nextIndex = xmlString.indexOf("<" + n.getNodeName(), nextIndex); nodeLength = xmlString.indexOf(">", nextIndex) - nextIndex + 1; } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) n; nextIndex = xmlString.indexOf("<?" + pi.getTarget(), nextIndex); } else if (n.getNodeType() == Node.TEXT_NODE) { String te = unexpandEntities(n, n.getNodeValue(), true); } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) n; nextIndex += "<?".length() + pi.getTarget().length() + "?>".length() + pi.getData().length();
switch (node.getNodeType()) { case Node.ATTRIBUTE_NODE: AttrImpl attr = (AttrImpl) node; return createComment(((Comment) node).getData()); case Node.DOCUMENT_TYPE_NODE: throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot copy node of type " + node.getNodeType()); for (int i = 0; i < attributes.getLength(); i++) { AttrImpl elementAttr = (AttrImpl) attributes.item(i); AttrImpl elementAttrCopy = (AttrImpl) shallowCopy(operation, elementAttr); notifyUserDataHandlers(operation, elementAttr, elementAttrCopy); return createEntityReference(node.getNodeName()); return createProcessingInstruction(pi.getTarget(), pi.getData());
IDatatype dom2dt(Node node){ IDatatype dt = null; switch(node.getNodeType()){ case Node.ELEMENT_NODE: case Node.DOCUMENT_NODE: ((ProcessingInstruction)node).getData()); break; dt = dom2dt(node, node.getNodeValue()); break; String value = node.getNodeValue(); NamedNodeMap map = node.getParentNode().getAttributes(); Node att = null; if (map != null){ att = map.getNamedItemNS(RDFNS, "datatype");
switch (copyNode.getNodeType()) { case Node.ATTRIBUTE_NODE: Node oldNode = copyNode; attribute(oldNode.getNamespaceURI(), oldNode.getPrefix(), oldNode.getLocalName(), oldNode.getNodeName(), startElement(oldElt.getNamespaceURI(), oldElt.getPrefix(), oldElt.getLocalName(), oldElt.getNodeName()); _xmlWriter.comment(((Comment) copyNode).getData()); break; ProcessingInstruction oldPi = (ProcessingInstruction) copyNode; _xmlWriter.processingInstruction(oldPi.getNodeName(), oldPi.getNodeValue()); break;
PageElement childElement; switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element ele = (Element) node; String tag = ele.getTagName(); def = ComponentRegistry.getInstance().get(tag); NamedNodeMap attributes = ele.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attr = attributes.item(i); childElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); PIParserBase piParser = piParsers.get(pi.getTarget()); throw new RuntimeException("Unrecognized prosessing instruction: " + pi.getTarget());
if (node instanceof Element) { Element element = (Element) node; o.print(level + "<" + element.getNodeName()); NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) o.print(" " + attrs.item(i).getNodeName() + "='" + attrs.item(i).getNodeValue() + "'"); o.println("> {" + node.getClass().getCanonicalName() + "}"); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) dump(o, nodes.item(i), level + " "); o.println(level + "</" + element.getNodeName() + ">"); } else if (node instanceof ProcessingInstruction) { o.println(level + "<?" + node.getNodeName() + " " + ((ProcessingInstruction) node).getData() + "?> {" + node.getClass().getCanonicalName() + "}"); } else if (node instanceof Comment) { o.println(level + "<!--" + ((Comment) node).getData() + "--> {" + node.getClass().getCanonicalName() + "}"); } else if (node instanceof Text) {
Element e = (Element) node; if (localName == null) { NamedNodeMap atts = e.getAttributes(); for (int i = 0; i < atts.getLength(); ++i) { result.add(atts.item(i)); namespaceUri = null; Attr attr = e.getAttributeNodeNS(namespaceUri, localName); if (attr != null) { result.add(attr); ProcessingInstruction pi = (ProcessingInstruction) node; if ("target".equals(localName)) { result.add(createAttribute(pi, "target", pi.getTarget())); } else if ("data".equals(localName)) { result.add(createAttribute(pi, "data", pi.getData())); } else {
public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing) throws XMLStreamException { switch (n.getNodeType()) { case Node.ELEMENT_NODE: writeElement((Element)n, writer, repairing); break; case Node.COMMENT_NODE: writer.writeComment(((Comment)n).getData()); break; case Node.CDATA_SECTION_NODE: break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; writer.writeProcessingInstruction(pi.getTarget(), pi.getData()); break; case Node.DOCUMENT_NODE: while (child != null) { writeNode(child, writer, repairing); child = child.getNextSibling();
if (child != null && child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String target = child.getNodeName(); if (target != null && target.equals("xml")) { //$NON-NLS-1$ pi = (ProcessingInstruction) child; child = child.getNextSibling(); pi.setData(declaration); Element element = document.getDocumentElement(); if (element != null) { element.setAttribute("xmlns", namespaceURI); //$NON-NLS-1$
/** * Processes the content of a Content element. * @param content the Content node. * @param tf the text fragment where to put the content. Use null to create one. * @return the modified text fragment (may be a new one). */ static TextFragment processContent (Element content, TextFragment tf) { if ( tf == null ) tf = new TextFragment(); // We assume only TEXT and PI nodes, no inner elements! Node node = content.getFirstChild(); while ( node != null ) { switch ( node.getNodeType() ) { case Node.TEXT_NODE: processText(tf, node.getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)node; tf.append(TagType.PLACEHOLDER, GetProcessingInstructionType(pi), String.format("<?%s %s?>", pi.getTarget(), pi.getTextContent())); break; default: throw new OkapiIOException("Unexpected content in <Content>: "+node.getNodeType()); } node = node.getNextSibling(); } return tf; }
Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); List<Element> resources = checkWadlResourcesInfo(doc, address, "/schemas/book.xsd", 2); assertEquals("", resources.get(0).getAttribute("type")); String type = resources.get(1).getAttribute("type"); String resourceTypeAddress = address + "/bookstoreImportResourceType.wadl#bookstoreType"; assertEquals(resourceTypeAddress, type); for (int i = 0; i < nd.getLength(); i++) { Node n = nd.item(i); if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String piData = ((ProcessingInstruction)n).getData(); int hRefStart = piData.indexOf("href=\""); if (hRefStart > 0) {
/** * @param xmlNode XML node * @param xmlStreamWriter XML stream writer * @throws XMLStreamException the XML stream exception */ public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (xmlNode instanceof Element) { addElement((Element) xmlNode, xmlStreamWriter); } else if (xmlNode instanceof Text) { xmlStreamWriter.writeCharacters(xmlNode.getNodeValue()); } else if (xmlNode instanceof CDATASection) { xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData()); } else if (xmlNode instanceof Comment) { xmlStreamWriter.writeComment(((Comment) xmlNode).getData()); } else if (xmlNode instanceof EntityReference) { xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue()); } else if (xmlNode instanceof ProcessingInstruction) { ProcessingInstruction procInst = (ProcessingInstruction) xmlNode; xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(), procInst.getData()); } else if (xmlNode instanceof Document) { writeToDocument((Document) xmlNode, xmlStreamWriter); } }