Java Code Examples for org.w3c.dom.DocumentFragment#getFirstChild()
The following examples show how to use
org.w3c.dom.DocumentFragment#getFirstChild() .
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: XsltFOFunctions.java From docx4j-export-FO with Apache License 2.0 | 6 votes |
public static DocumentFragment createBlockForSdt(FOConversionContext context, NodeIterator pPrNodeIt, String pStyleVal, NodeIterator childResults, String tag) { DocumentFragment docfrag = createBlock(context, pPrNodeIt, pStyleVal, childResults, true); // Set margins, but only for a shading container, // not a borders container if (tag.equals(Containerization.TAG_SHADING) && docfrag!=null) { // docfrag.getNodeName() is #document-fragment Node foBlock = docfrag.getFirstChild(); if (foBlock!=null) { ((Element)foBlock).setAttribute("margin-top", "0in"); ((Element)foBlock).setAttribute("margin-bottom", "0in"); // ((Element)foBlock).setAttribute("padding-top", "0in"); // ((Element)foBlock).setAttribute("padding-bottom", "0in"); } } return docfrag; }
Example 2
Source File: AbstractBindingBuilder.java From cxf with Apache License 2.0 | 6 votes |
protected Element cloneElement(Element el) { Document doc = secHeader.getSecurityHeaderElement().getOwnerDocument(); if (!doc.equals(el.getOwnerDocument())) { XMLStreamReader reader = StaxUtils.createXMLStreamReader(el); DocumentFragment fragment = doc.createDocumentFragment(); W3CDOMStreamWriter writer = new W3CDOMStreamWriter(fragment); try { StaxUtils.copy(reader, writer); return (Element)fragment.getFirstChild(); } catch (XMLStreamException ex) { LOG.log(Level.FINE, "Error cloning security element", ex); } } return el; }
Example 3
Source File: XsltFOFunctions.java From docx4j-export-FO with Apache License 2.0 | 6 votes |
/** * Use RunFontSelector to determine the correct font for the list item label. * * @param context * @param foListItemLabelBody * @param pPr * @param rPr * @param text */ protected static void setFont(RunFontSelector runFontSelector, Element foListItemLabelBody, PPr pPr, RPr rPr, String text) { DocumentFragment result = (DocumentFragment)runFontSelector.fontSelector(pPr, rPr, text); log.debug(XmlUtils.w3CDomNodeToString(result)); // eg <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Times New Roman">1)</fo:inline> // Now get the attribute value if (result!=null && result.getFirstChild()!=null) { Attr attr = ((Element)result.getFirstChild()).getAttributeNode("font-family"); if (attr!=null) { foListItemLabelBody.setAttribute("font-family", attr.getValue()); } } }
Example 4
Source File: NodesTest.java From caja with Apache License 2.0 | 6 votes |
public final void testRenderWithUnknownNamespace() throws Exception { DocumentFragment fragment = xmlFragment(fromString( "" + "<foo xmlns='http://www.w3.org/XML/1998/namespace'" + " xmlns:bar='http://bobs.house.of/XML&BBQ'>" + "<bar:baz boo='howdy' xml:lang='es'/>" + "</foo>")); // Remove any XMLNS attributes and prefixes. Element el = (Element) fragment.getFirstChild(); while (el.getAttributes().getLength() != 0) { el.removeAttributeNode((Attr) el.getAttributes().item(0)); } el.setPrefix(""); el.getFirstChild().setPrefix(""); assertEquals( "" + "<xml:foo>" + "<_ns1:baz xmlns:_ns1=\"http://bobs.house.of/XML&BBQ\"" + " boo=\"howdy\" xml:lang=\"es\"></_ns1:baz>" + "</xml:foo>", Nodes.render(fragment, MarkupRenderMode.XML)); }
Example 5
Source File: MXFEssenceReader.java From photon with Apache License 2.0 | 6 votes |
/** * A method that returns a list of EssenceDescriptor objects referenced by the Source Packages in the Essence * * @return List of DOM Nodes corresponding to every EssenceDescriptor in the essence * @throws IOException - any I/O related error will be exposed through an IOException */ public List<Node> getEssenceDescriptorsDOMNodes() throws IOException{ try { List<InterchangeObject.InterchangeObjectBO> essenceDescriptors = this.getHeaderPartition().getEssenceDescriptors(); List<Node> essenceDescriptorNodes = new ArrayList<>(); for (InterchangeObject.InterchangeObjectBO essenceDescriptor : essenceDescriptors) { KLVPacket.Header essenceDescriptorHeader = essenceDescriptor.getHeader(); List<KLVPacket.Header> subDescriptorHeaders = this.getSubDescriptorKLVHeader(essenceDescriptor); /*Create a dom*/ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); DocumentFragment documentFragment = this.getEssenceDescriptorAsDocumentFragment(document, essenceDescriptorHeader, subDescriptorHeaders); Node node = documentFragment.getFirstChild(); essenceDescriptorNodes.add(node); } return essenceDescriptorNodes; } catch(ParserConfigurationException e){ throw new IMFException(e); } }
Example 6
Source File: UtilXml.java From scipio-erp with Apache License 2.0 | 6 votes |
/** Return a List of Element objects that are children of the given DocumentFragment */ public static List<? extends Element> childElementList(DocumentFragment fragment) { if (fragment == null) { return null; } List<Element> elements = new LinkedList<>(); Node node = fragment.getFirstChild(); if (node != null) { do { if (node.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) node; elements.add(childElement); } } while ((node = node.getNextSibling()) != null); } return elements; }
Example 7
Source File: XmlElementStack.java From caja with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ public void finish(FilePosition endOfDocument) throws IllegalDocumentStateException { stripIgnorableText(); DocumentFragment root = getRootElement(); if (needsDebugData) { FilePosition rootStart = Nodes.getFilePositionFor(root); if (rootStart == null || InputSource.UNKNOWN.equals(rootStart.source())) { if (root.getFirstChild() == null) { rootStart = endOfDocument; } else { rootStart = Nodes.getFilePositionFor(root.getFirstChild()); } } if (rootStart.startCharInFile() <= endOfDocument.startCharInFile()) { Nodes.setFilePositionFor( root, FilePosition.span(rootStart, endOfDocument)); } } int nOpen = getNOpenElements(); if (nOpen != 1) { Element openEl = getElement(nOpen - 1); throw new IllegalDocumentStateException(new Message( DomParserMessageType.MISSING_END, endOfDocument, MessagePart.Factory.valueOf(openEl.getTagName()), Nodes.getFilePositionFor(openEl))); } }
Example 8
Source File: AbstractApplicationComposition.java From photon with Apache License 2.0 | 5 votes |
private List<Node> getEssenceDescriptorDOMNodes(Composition.HeaderPartitionTuple headerPartitionTuple) throws IOException { IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl(); List<InterchangeObject.InterchangeObjectBO> essenceDescriptors = headerPartitionTuple.getHeaderPartition().getEssenceDescriptors(); List<Node> essenceDescriptorNodes = new ArrayList<>(); for (InterchangeObject.InterchangeObjectBO essenceDescriptor : essenceDescriptors) { try { KLVPacket.Header essenceDescriptorHeader = essenceDescriptor.getHeader(); List<KLVPacket.Header> subDescriptorHeaders = this.getSubDescriptorKLVHeader(headerPartitionTuple.getHeaderPartition(), essenceDescriptor); /*Create a dom*/ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); DocumentFragment documentFragment = this.getEssenceDescriptorAsDocumentFragment(document, headerPartitionTuple, essenceDescriptorHeader, subDescriptorHeaders); Node node = documentFragment.getFirstChild(); essenceDescriptorNodes.add(node); } catch (ParserConfigurationException e) { imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.INTERNAL_ERROR, IMFErrorLogger.IMFErrors .ErrorLevels.FATAL, e.getMessage()); } } if(imfErrorLogger.hasFatalErrors()) { throw new IMFException("Failed to get Essence Descriptor for a resource", imfErrorLogger); } return essenceDescriptorNodes; }
Example 9
Source File: IMFTrackFileCPLBuilder.java From photon with Apache License 2.0 | 5 votes |
private void buildEssenceDescriptorList(List<String> uuidList, IMFErrorLogger imfErrorLogger) throws IOException{ try { List<EssenceDescriptorBaseType> essenceDescriptorList = this.cplRoot.getEssenceDescriptorList().getEssenceDescriptor(); List<InterchangeObject.InterchangeObjectBO> essenceDescriptors = this.imfTrackFileReader.getEssenceDescriptors(imfErrorLogger); for(InterchangeObject.InterchangeObjectBO essenceDescriptor : essenceDescriptors) { KLVPacket.Header essenceDescriptorHeader = essenceDescriptor.getHeader(); List<KLVPacket.Header> subDescriptorHeaders = this.imfTrackFileReader.getSubDescriptorKLVHeader(essenceDescriptor, imfErrorLogger); /*Create a dom*/ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); EssenceDescriptorBaseType essenceDescriptorBaseType = new EssenceDescriptorBaseType(); String uuid = IMFUUIDGenerator.getInstance().getUrnUUID(); essenceDescriptorBaseType.setId(uuid); uuidList.add(uuid); DocumentFragment documentFragment = this.getEssenceDescriptorAsDocumentFragment(document, essenceDescriptorHeader, subDescriptorHeaders, imfErrorLogger); Node node = documentFragment.getFirstChild(); essenceDescriptorBaseType.getAny().add(node); essenceDescriptorList.add(essenceDescriptorBaseType); } } catch(ParserConfigurationException e){ imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_CPL_ERROR, IMFErrorLogger.IMFErrors .ErrorLevels.FATAL, e.getMessage()); throw new IMFException(e); } }
Example 10
Source File: DOMNodeObjectModelTest.java From photon with Apache License 2.0 | 4 votes |
public List<DOMNodeObjectModel> setUp(File inputFile) throws IOException, ParserConfigurationException { IMFErrorLogger imfErrorLogger1 = new IMFErrorLoggerImpl(); List<Node> essenceDescriptorNodes1 = new ArrayList<>(); List<DOMNodeObjectModel> essenceDescriptorDOMNodeObjectModels1 = new ArrayList<>(); ResourceByteRangeProvider resourceByteRangeProvider1 = new FileByteRangeProvider(inputFile); byte[] bytes1 = resourceByteRangeProvider1.getByteRangeAsBytes(0, resourceByteRangeProvider1.getResourceSize() - 1); ByteProvider byteProvider1 = new ByteArrayDataProvider(bytes1); HeaderPartition headerPartition1 = new HeaderPartition(byteProvider1, 0L, bytes1.length, imfErrorLogger1); List<InterchangeObject.InterchangeObjectBO> essenceDescriptors1 = headerPartition1.getEssenceDescriptors(); for (InterchangeObject.InterchangeObjectBO essenceDescriptor : essenceDescriptors1) { List<KLVPacket.Header> subDescriptorHeaders = new ArrayList<>(); List<InterchangeObject.InterchangeObjectBO> subDescriptors = headerPartition1.getSubDescriptors(essenceDescriptor); for (InterchangeObject.InterchangeObjectBO subDescriptorBO : subDescriptors) { if (subDescriptorBO != null) { subDescriptorHeaders.add(subDescriptorBO.getHeader()); } } /*Create a dom*/ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); //DocumentFragment documentFragment = this.getEssenceDescriptorAsDocumentFragment(document, headerPartitionTuple, essenceDescriptorHeader, subDescriptorHeaders); PrimerPack primerPack = headerPartition1.getPrimerPack(); RegXMLLibHelper regXMLLibHelper = new RegXMLLibHelper(primerPack.getHeader(), getByteProvider(resourceByteRangeProvider1, primerPack.getHeader())); Triplet essenceDescriptorTriplet = regXMLLibHelper.getTripletFromKLVHeader(essenceDescriptor.getHeader(), getByteProvider(resourceByteRangeProvider1, essenceDescriptor.getHeader())); //DocumentFragment documentFragment = this.regXMLLibHelper.getDocumentFragment(essenceDescriptorTriplet, document); /*Get the Triplets corresponding to the SubDescriptors*/ List<Triplet> subDescriptorTriplets = new ArrayList<>(); for (KLVPacket.Header subDescriptorHeader : subDescriptorHeaders) { subDescriptorTriplets.add(regXMLLibHelper.getTripletFromKLVHeader(subDescriptorHeader, this.getByteProvider(resourceByteRangeProvider1, subDescriptorHeader))); } DocumentFragment documentFragment = regXMLLibHelper.getEssenceDescriptorDocumentFragment(essenceDescriptorTriplet, subDescriptorTriplets, document, imfErrorLogger1); Node node = documentFragment.getFirstChild(); essenceDescriptorNodes1.add(node); essenceDescriptorDOMNodeObjectModels1.add(new DOMNodeObjectModel(node)); } return essenceDescriptorDOMNodeObjectModels1; }
Example 11
Source File: DomParser.java From caja with Apache License 2.0 | 4 votes |
/** Parse a document returning the document element. */ private Element parseDocument(String features) throws ParseException { Function<DOMImplementation, DocumentType> doctypeMaker = findDoctype(); Document doc = makeDocument(doctypeMaker, features, domImpl); OpenElementStack elementStack = makeElementStack(doc, mq); // Make sure the elementStack is empty. elementStack.open(false); skipTopLevelDocIgnorables(true); do { parseDom(elementStack); skipTopLevelDocIgnorables(false); } while (!tokens.isEmpty()); FilePosition endPos = checkEnd(elementStack); DocumentFragment root = elementStack.getRootElement(); Node firstChild = root.getFirstChild(); if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) { throw new ParseException(new Message( DomParserMessageType.MISSING_DOCUMENT_ELEMENT, endPos)); } // Check that there isn't any extraneous content after the root element. for (Node child = firstChild.getNextSibling(); child != null; child = child.getNextSibling()) { switch (child.getNodeType()) { case Node.COMMENT_NODE: case Node.DOCUMENT_TYPE_NODE: continue; case Node.TEXT_NODE: if ("".equals(child.getNodeValue().trim())) { continue; } break; default: break; } throw new ParseException(new Message( DomParserMessageType.MISPLACED_CONTENT, Nodes.getFilePositionFor(child))); } Nodes.setFilePositionFor(doc, Nodes.getFilePositionFor(root)); doc.appendChild(firstChild); if (elementStack.needsNamespaceFixup()) { firstChild = fixup(firstChild, ns); } return (Element) firstChild; }
Example 12
Source File: IMPBuilder.java From photon with Apache License 2.0 | 4 votes |
public static Map<UUID, List<Node>> buildEDLForVirtualTracks (Map<UUID, IMPBuilder.IMFTrackFileMetadata> imfTrackFileMetadataMap, List<? extends Composition.VirtualTrack> virtualTrackList, IMFErrorLogger imfErrorLogger) throws IOException, ParserConfigurationException{ Map<UUID, List<Node>> imfEssenceDescriptorMap = new HashMap<>(); for(Composition.VirtualTrack virtualTrack : virtualTrackList) { if (!(virtualTrack instanceof IMFEssenceComponentVirtualTrack)) { continue; // Skip non-essence tracks } Set<UUID> trackResourceIds = IMFEssenceComponentVirtualTrack.class.cast(virtualTrack).getTrackResourceIds(); /** * Create the RegXML representation of the EssenceDescriptor metadata for every Resource of every VirtualTrack * of the Composition */ for (UUID uuid : trackResourceIds) { IMPBuilder.IMFTrackFileMetadata imfTrackFileMetadata = imfTrackFileMetadataMap.get(uuid); if (imfTrackFileMetadata == null) { throw new IMFAuthoringException(String.format("TrackFileHeaderMetadata for Track Resource Id %s within VirtualTrack Id %s is absent", uuid.toString(), virtualTrack.getTrackID())); } ByteProvider byteProvider = new ByteArrayDataProvider(imfTrackFileMetadata.getHeaderPartition()); ResourceByteRangeProvider resourceByteRangeProvider = new ByteArrayByteRangeProvider(imfTrackFileMetadata.getHeaderPartition()); //Create the HeaderPartition HeaderPartition headerPartition = new HeaderPartition(byteProvider, 0L, (long) imfTrackFileMetadata.getHeaderPartition().length, imfErrorLogger); MXFOperationalPattern1A.HeaderPartitionOP1A headerPartitionOP1A = MXFOperationalPattern1A.checkOperationalPattern1ACompliance(headerPartition, imfErrorLogger); IMFConstraints.checkIMFCompliance(headerPartitionOP1A, imfErrorLogger); List<InterchangeObject.InterchangeObjectBO> essenceDescriptors = headerPartition.getEssenceDescriptors(); for (InterchangeObject.InterchangeObjectBO essenceDescriptor : essenceDescriptors) { KLVPacket.Header essenceDescriptorHeader = essenceDescriptor.getHeader(); List<KLVPacket.Header> subDescriptorHeaders = new ArrayList<>(); List<InterchangeObject.InterchangeObjectBO> subDescriptors = headerPartition.getSubDescriptors(essenceDescriptor); for (InterchangeObject.InterchangeObjectBO subDescriptorBO : subDescriptors) { if (subDescriptorBO != null) { subDescriptorHeaders.add(subDescriptorBO.getHeader()); } } /*Create a dom*/ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); RegXMLLibHelper regXMLLibHelper = new RegXMLLibHelper(headerPartition.getPrimerPack().getHeader(), getByteProvider(resourceByteRangeProvider, headerPartition.getPrimerPack().getHeader())); DocumentFragment documentFragment = getEssenceDescriptorAsDocumentFragment(regXMLLibHelper, document, essenceDescriptorHeader, subDescriptorHeaders, resourceByteRangeProvider, imfErrorLogger); Node node = documentFragment.getFirstChild(); imfEssenceDescriptorMap.put(uuid, Arrays.asList(node)); } } } return imfEssenceDescriptorMap; }
Example 13
Source File: XsltFOFunctions.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
/** * This is invoked on every paragraph, whether it has a pPr or not. * * @param wmlPackage * @param pPrNodeIt * @param pStyleVal * @param childResults - the already transformed contents of the paragraph. * @return */ public static DocumentFragment createBlockForPPr( FOConversionContext context, NodeIterator pPrNodeIt, String pStyleVal, NodeIterator childResults) { DocumentFragment df = createBlock( context, pPrNodeIt, pStyleVal, childResults, false); // Arabic (and presumably Hebrew) fix // If we have inline direction="rtl" (created by TextDirection class) // wrap the inline with: // <bidi-override direction="rtl" unicode-bidi="embed"> /* See further: From: Glenn Adams <[email protected]> Date: Fri, Mar 21, 2014 at 8:41 AM Subject: Re: right align arabic in table-cell To: FOP Users <[email protected]> */ Element block = (Element)df.getFirstChild(); NodeList blockChildren = block.getChildNodes(); for (int i = 0 ; i <blockChildren.getLength(); i++ ) { if (blockChildren.item(i) instanceof Element) { Element inline = (Element)blockChildren.item(i); if (inline !=null && inline.getAttribute("direction")!=null && inline.getAttribute("direction").equals("rtl")) { inline.removeAttribute("direction"); Element bidiOverride = df.getOwnerDocument().createElementNS("http://www.w3.org/1999/XSL/Format", "fo:bidi-override"); bidiOverride.setAttribute("unicode-bidi", "embed" ); bidiOverride.setAttribute("direction", "rtl" ); block.replaceChild(bidiOverride, inline); bidiOverride.appendChild(inline); } } } if (foContainsElement(block, "leader")) { // ptab to leader implementation: // for leader to work as expected in fop, we need text-align-last; see http://xmlgraphics.apache.org/fop/faq.html#leader-expansion // this code adds that. // Note that it doesn't seem to be necessary for leader in TOC, but it doesn't hurt block.setAttribute("text-align-last", "justify"); } return df; }
Example 14
Source File: EncoderDecoder11Impl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(ack, doc); return (Element)doc.getFirstChild(); }
Example 15
Source File: EncoderDecoder11Impl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeIdentifier(Identifier id) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(id, doc); return (Element)doc.getFirstChild(); }
Example 16
Source File: EncoderDecoder10Impl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(VersionTransformer.convert200502(ack), doc); return (Element)doc.getFirstChild(); }
Example 17
Source File: EncoderDecoder10Impl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeIdentifier(Identifier id) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(VersionTransformer.convert200502(id), doc); return (Element)doc.getFirstChild(); }
Example 18
Source File: EncoderDecoder10AImpl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(VersionTransformer.convert200502wsa15(ack), doc); return (Element)doc.getFirstChild(); }
Example 19
Source File: EncoderDecoder10AImpl.java From cxf with Apache License 2.0 | 4 votes |
public Element encodeIdentifier(Identifier id) throws JAXBException { DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment(); Marshaller marshaller = getContext().createMarshaller(); marshaller.marshal(VersionTransformer.convert200502wsa15(id), doc); return (Element)doc.getFirstChild(); }
Example 20
Source File: StaxUtils.java From cxf with Apache License 2.0 | 4 votes |
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.TEXT_NODE: writer.writeCharacters(((Text)n).getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(((Comment)n).getData()); break; case Node.CDATA_SECTION_NODE: writer.writeCData(((CDATASection)n).getData()); 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: writeDocument((Document)n, writer, repairing); break; case Node.DOCUMENT_FRAGMENT_NODE: { DocumentFragment frag = (DocumentFragment)n; Node child = frag.getFirstChild(); while (child != null) { writeNode(child, writer, repairing); child = child.getNextSibling(); } break; } case Node.DOCUMENT_TYPE_NODE: try { if (((DocumentType)n).getTextContent() != null) { writer.writeDTD(((DocumentType)n).getTextContent()); } } catch (UnsupportedOperationException ex) { //can we ignore? DOM writers really don't allow this //as there isn't a way to write a DTD in dom } break; default: throw new IllegalStateException("Found type: " + n.getClass().getName()); } }