method: "XML"
charset: "UTF-8"
indenting: TRUE
indent-width: 2
line-width: 80
preserve-space: FALSE
omit-XML-declaration: FALSE
omit-DOCTYPE: TRUE
@param ele
@param out
@throws IOException
353072
public static void writeConsoleNoDocType(Document ele, Writer out)
    throws IOException {
        XMLSerializer serializer =
                new XMLSerializer(out, CONSOLE_NO_DOCTYPE);
        serializer.serialize(ele);
    }
1220420
public void write(Writer out)
            throws XmlModelWriterException, IOException
    {
        try
        {
            DOMSource domSource = new DOMSource(_doc);
            StreamResult streamResult = new StreamResult(out);
            TransformerFactory tf = TransformerFactory.newInstance();
            tf.setAttribute("indent-number", new Integer(INDENT_LEN));
            Transformer serializer = tf.newTransformer();
            if (_publicID != null) {
                serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, _publicID);
            }
            if (_systemID != null) {
                serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, _systemID);
            }
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.transform(domSource, streamResult);
        }
        catch (TransformerException e)
        {
            throw new XmlModelWriterException(e);
        }
    }
385001
public void toAngelCodeXML(PrintStream out, String imageName) throws IOException {
		try {
			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document document = builder.newDocument();
			Element root = document.createElement("font");
			document.appendChild(root);
			
			Element info = document.createElement("info");
			info.setAttribute("face",fontName);
			info.setAttribute("size",""+size);
			info.setAttribute("bold","0");
			info.setAttribute("italic","0");
			info.setAttribute("charSet",setName);
			info.setAttribute("unicode",""+0);
			info.setAttribute("stretchH",""+100);
			info.setAttribute("smooth",""+0);
			info.setAttribute("aa",""+0);
			info.setAttribute("padding","0,0,0,0");
			info.setAttribute("spacing","0,0");
			root.appendChild(info);
			Element common = document.createElement("common");
			common.setAttribute("lineHeight",""+lineHeight);
			common.setAttribute("base","0");
			common.setAttribute("scaleW",""+width);
			common.setAttribute("scaleH",""+height);
			common.setAttribute("pages","1");
			common.setAttribute("packed","0");
			root.appendChild(common);
			Element pages = document.createElement("pages");
			Element page = document.createElement("page");
			page.setAttribute("id","0");
			page.setAttribute("file",imageName);
			root.appendChild(pages);
			pages.appendChild(page);
			
			Element charsElement = document.createElement("chars");
			charsElement.setAttribute("count",""+chars.size());
			root.appendChild(charsElement);
			for (int i=0;i<chars.size();i++) {
				CharData c = (CharData) chars.get(i);
				Element charElement = document.createElement("char");
				
				charElement.setAttribute("id", ""+c.getID());
				charElement.setAttribute("x", ""+c.getX());
				charElement.setAttribute("y", ""+c.getY());
				charElement.setAttribute("width", ""+c.getWidth());
				charElement.setAttribute("height", ""+c.getHeight());
				charElement.setAttribute("xoffset", "0");
				charElement.setAttribute("yoffset", ""+c.getYOffset());
				charElement.setAttribute("xadvance", ""+c.getXAdvance());
				charElement.setAttribute("page", "0");
				charElement.setAttribute("chnl", "0");
				charsElement.appendChild(charElement);
			}
			
			Element kernsElement = document.createElement("kernings");
			kernsElement.setAttribute("count",""+kerning.size());
			root.appendChild(kernsElement);
			for (int i=0;i<kerning.size();i++) {
				KerningData k = (KerningData) kerning.get(i);
				Element kernElement = document.createElement("kerning");
				
				kernElement.setAttribute("first", ""+k.first);
				kernElement.setAttribute("second", ""+k.second);
				kernElement.setAttribute("amount", ""+k.offset);
				kernsElement.appendChild(kernElement);
			}
			
			Result result = new StreamResult(new OutputStreamWriter(out,
					"utf-8"));
			DOMSource source = new DOMSource(document);
			TransformerFactory factory = TransformerFactory.newInstance();
			factory.setAttribute("indent-number", new Integer(2));
			Transformer xformer = factory.newTransformer();
			xformer.setOutputProperty(OutputKeys.INDENT, "yes");
			
			xformer.transform(source, result);
		} catch (Exception e) {
			e.printStackTrace();
			IOException x = new IOException();
			x.initCause(e);
			
			throw x;
		}
	}
1196450
protected void checkXmlSpaceAttr(int type, WordResolver enumValues)
        throws XMLStreamException
    {
        boolean ok = (type == DTDAttribute.TYPE_ENUMERATED);
        if (ok) {
            switch (enumValues.size()) {
            case 1:
                ok = (enumValues.find("preserve") != null)
                    || (enumValues.find("default") != null);
                break;
            case 2:
                ok = (enumValues.find("preserve") != null)
                    && (enumValues.find("default") != null);
                break;
            default:
                ok = false;
            }
        }
        
        if (!ok) {
            _reportVCViolation(ErrorConsts.ERR_DTD_XML_SPACE);
        }
    }
153627
def xmlindent(elem, level=0, spacer='  '):
    
    i = "\n" + level * spacer
    if len(elem):
        if not elem.text or not elem.text.strip():
            elem.text = i + spacer
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
        for elem in elem:
            xmlindent(elem, level + 1)
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i
1303913
def as_log_output(self):
        
        elem = self.to_element()
        for attrname in self.sensitive_attributes:
            for sensitive_el in elem.iter(attrname):
                sensitive_el.text = 'XXXXXXXXXXXXXXXX'
        return ElementTreeBuilder.tostring(elem, encoding='UTF-8')
205249
public void write() throws IOException {
        OutputStream outStream = null;
        XMLStreamWriter out = null;
        try {
            outStream = new FileOutputStream(jobFile);
            out = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, "UTF-8");
            out.writeStartDocument();
            out.writeStartElement(ELEMENT_JOB);
            for (final Map.Entry<String, Object> e: prop.entrySet()) {
                out.writeStartElement(ELEMENT_PROPERTY);
                out.writeAttribute(ATTRIBUTE_NAME, e.getKey());
                if (e.getValue() instanceof String) {
                    out.writeStartElement(ELEMENT_STRING);
                    out.writeCharacters(e.getValue().toString());
                    out.writeEndElement(); //string
                } else if (e.getValue() instanceof Set) {
                    out.writeStartElement(ELEMENT_SET);
                    final Set<?> s = (Set<?>) e.getValue();
                    for (final Object o: s) {
                        out.writeStartElement(ELEMENT_STRING);
                        out.writeCharacters(o.toString());
                        out.writeEndElement(); //string
                    }
                    out.writeEndElement(); //set
                } else if (e.getValue() instanceof Map) {
                    out.writeStartElement(ELEMENT_MAP);
                    final Map<?, ?> s = (Map<?, ?>) e.getValue();
                    for (final Map.Entry<?, ?> o: s.entrySet()) {
                        out.writeStartElement(ELEMENT_ENTRY);
                        out.writeAttribute(ATTRIBUTE_KEY, o.getKey().toString());
                        out.writeStartElement(ELEMENT_STRING);
                        out.writeCharacters(o.getValue().toString());
                        out.writeEndElement(); //string
                        out.writeEndElement(); //entry
                    }
                    out.writeEndElement(); //string
                } else {
                    out.writeStartElement(e.getValue().getClass().getName());
                    out.writeCharacters(e.getValue().toString());
                    out.writeEndElement(); //string
                }
                out.writeEndElement(); //property
            }
            out.writeStartElement(ELEMENT_FILES);
            for (final FileInfo i: files.values()) {
                out.writeStartElement(ELEMENT_FILE);
                if (i.src != null) {
                    out.writeAttribute(ATTRIBUTE_SRC, i.src.toString());
                }
                out.writeAttribute(ATTRIBUTE_URI, i.uri.toString());
                out.writeAttribute(ATTRIBUTE_PATH, i.file.getPath());
                if (i.result != null) {
                    out.writeAttribute(ATTRIBUTE_RESULT, i.result.toString());
                }
                if (i.format != null) {
                    out.writeAttribute(ATTRIBUTE_FORMAT, i.format);
                }
                try {
                    for (Map.Entry<String, Field> e: attrToFieldMap.entrySet()) {
                        final boolean v = e.getValue().getBoolean(i);
                        if (v) {
                            out.writeAttribute(e.getKey(), Boolean.TRUE.toString());
                        }
                    }
                } catch (final IllegalAccessException ex) {
                    throw new RuntimeException(ex);
                }
                out.writeEndElement(); //file
            }
            out.writeEndElement(); //files
            out.writeEndElement(); //job
            out.writeEndDocument();
        } catch (final IOException e) {
            throw new IOException("Failed to write file: " + e.getMessage());
        } catch (final XMLStreamException e) {
            throw new IOException("Failed to serialize job file: " + e.getMessage());
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (final XMLStreamException e) {
                    throw new IOException("Failed to close file: " + e.getMessage());
                }
            }
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (final IOException e) {
                    throw new IOException("Failed to close file: " + e.getMessage());
                }
            }
        }
        lastModified = jobFile.lastModified();
    }
851104
private static void escapeXml(final char[] text, final int offset, final int len, final Writer writer,
                                 final XmlEscapeSymbols symbols, final XmlEscapeType type, final XmlEscapeLevel level)
                                 throws IOException {

        if (writer == null) {
            throw new IllegalArgumentException("Argument 'writer' cannot be null");
        }

        if (type == null) {
            throw new IllegalArgumentException("The 'type' argument cannot be null");
        }

        if (level == null) {
            throw new IllegalArgumentException("The 'level' argument cannot be null");
        }

        final int textLen = (text == null? 0 : text.length);

        if (offset < 0 || offset > textLen) {
            throw new IllegalArgumentException(
                    "Invalid (offset, len). offset=" + offset + ", len=" + len + ", text.length=" + textLen);
        }

        if (len < 0 || (offset + len) > textLen) {
            throw new IllegalArgumentException(
                    "Invalid (offset, len). offset=" + offset + ", len=" + len + ", text.length=" + textLen);
        }

        XmlEscapeUtil.escape(text, offset, len, writer, symbols, type, level);

    }
173024
public void writeXmlDocument(Document document, File file) throws IOException {
        try {
            Transformer tr = transformerFactory.newTransformer();
            tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            tr.setOutputProperty(OutputKeys.INDENT, "yes");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            tr.transform(new DOMSource(document), new StreamResult(fileOutputStream));
            fileOutputStream.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage(), e);
        }
    }
1290706
private void _emitXMLLines (final MarkdownHCStack aOut, final Line aLines)
  {
    Line aLine = aLines;
    if (m_aConfig.isSafeMode ())
    {
      final StringBuilder aTmpSB = new StringBuilder ();
      while (aLine != null)
      {
        if (!aLine.m_bIsEmpty)
          aTmpSB.append (aLine.m_sValue.trim ());
        aLine = aLine.m_aNext;
      }
      final String sIn = aTmpSB.toString ();
      for (int nPos = 0; nPos < sIn.length (); nPos++)
      {
        if (sIn.charAt (nPos) == '<')
        {
          aTmpSB.setLength (0);
          final int nNewPos = MarkdownHelper.readXMLElement (aTmpSB, sIn, nPos, m_aConfig.isSafeMode ());
          if (nNewPos != -1)
          {
            // XXX Is this correct???
            aOut.append (aTmpSB.toString ());
            nPos = nNewPos;
          }
          else
          {
            aOut.append (sIn.charAt (nPos));
          }
        }
        else
        {
          aOut.append (sIn.charAt (nPos));
        }
      }
    }
    else
    {
      final StringBuilder aXML = new StringBuilder ();
      int nLines = 0;
      while (aLine != null)
      {
        if (!aLine.m_bIsEmpty)
        {
          aXML.append (aLine.m_sValue.trim ());
          ++nLines;
        }
        aLine = aLine.m_aNext;
      }

      String sXML = aXML.toString ();
      if (nLines == 1 && !sXML.contains ("/>") && !sXML.contains ("</"))
      {
        // Unclosed tag - parse as self-closed tag and push to stack
        // Workaround e.g. for <hr>
        sXML = sXML.substring (0, sXML.length () - 1) + "/>";
      }

      final IMicroDocument aDoc = MicroReader.readMicroXML (sXML);
      if (aDoc == null)
        throw new MarkdownException ("Failed to parse XML: " + sXML);

      aOut.append (new HCDOMWrapper (aDoc.getDocumentElement ().detachFromParent ()));
    }
  }
188863
@Override
    public void handleXmlDeclaration(
            final char[] buffer,
            final int keywordOffset, final int keywordLen, final int keywordLine, final int keywordCol,
            final int versionOffset, final int versionLen, final int versionLine, final int versionCol,
            final int encodingOffset, final int encodingLen, final int encodingLine, final int encodingCol,
            final int standaloneOffset, final int standaloneLen, final int standaloneLine, final int standaloneCol,
            final int outerOffset, final int outerLen, final int line, final int col) throws ParseException {

        if (!this.insideAllSelectorMatchingBlock) {

            this.someSelectorsMatch = false;
            for (int i = 0; i < this.selectorsLen; i++) {

                if (this.matchingMarkupLevelsPerSelector[i] > this.markupLevel) {
                    this.selectorMatches[i] =
                            this.selectorFilters[i].matchXmlDeclaration(true, this.markupLevel, this.markupBlocks[this.markupLevel]);
                    if (this.selectorMatches[i]) {
                        this.someSelectorsMatch = true;
                    }
                } else {
                    this.selectorMatches[i] = true;
                    this.someSelectorsMatch = true;
                }

            }

            if (this.someSelectorsMatch) {
                markCurrentSelection();
                this.selectedHandler.handleXmlDeclaration(
                        buffer, keywordOffset, keywordLen, keywordLine, keywordCol,
                        versionOffset, versionLen, versionLine, versionCol,
                        encodingOffset, encodingLen, encodingLine, encodingCol,
                        standaloneOffset, standaloneLen, standaloneLine, standaloneCol,
                        outerOffset, outerLen, line, col);
                unmarkCurrentSelection();
                return;
            }

            unmarkCurrentSelection();
            this.nonSelectedHandler.handleXmlDeclaration(
                    buffer, keywordOffset, keywordLen, keywordLine, keywordCol,
                    versionOffset, versionLen, versionLine, versionCol,
                    encodingOffset, encodingLen, encodingLine, encodingCol,
                    standaloneOffset, standaloneLen, standaloneLine, standaloneCol,
                    outerOffset, outerLen, line, col);
            return;

        }

        markCurrentSelection();
        this.selectedHandler.handleXmlDeclaration(
                buffer, keywordOffset, keywordLen, keywordLine, keywordCol,
                versionOffset, versionLen, versionLine, versionCol,
                encodingOffset, encodingLen, encodingLine, encodingCol,
                standaloneOffset, standaloneLen, standaloneLine, standaloneCol,
                outerOffset, outerLen, line, col);
        unmarkCurrentSelection();

    }
844528
@Override
   public void writeXmlBody(Definition def, Writer out) throws IOException
   {
      writeConnectorVersion(out);

      int indent = 1;
      writeIndent(out, indent);
      out.write("<display-name>Display Name</display-name>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<vendor-name>Red Hat Inc</vendor-name>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<spec-version>1.0</spec-version>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<eis-type>Test RA</eis-type>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<version>0.1</version>");
      writeEol(out);

      writeIndent(out, indent);
      out.write("<resourceadapter>");
      writeEol(out);

      writeOutbound(def, out, indent + 1);

      writeIndent(out, indent);
      out.write("</resourceadapter>");
      writeEol(out);
      out.write("</connector>");
      writeEol(out);
   }
93678
public static void writeXML(DocumentFragment fragment, OutputStream stream) throws IOException {
		assert fragment != null : AssertMessages.notNullParameter(0);
		assert stream != null : AssertMessages.notNullParameter(1);
		writeNode(fragment, stream);
	}
276258
static void serialize(final Document doc, final OutputStream os, final String encoding)
        throws TransformerFactoryConfigurationError, TransformerException, IOException
  {
    if (doc == null)
      throw new IllegalArgumentException("No document provided.");

    if (os == null)
      throw new IllegalArgumentException("No output stream provided");

    if (encoding == null || encoding.isEmpty())
      throw new IllegalArgumentException("No encoding provided.");

    final TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setAttribute("indent-number", Integer.valueOf(2));
    final Transformer t = transformerFactory.newTransformer();

    t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    t.setOutputProperty(OutputKeys.METHOD, "xml");
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty(OutputKeys.ENCODING, encoding);

    final OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
    t.transform(new DOMSource(doc), new StreamResult(osw));
    osw.flush();
  }
1219972
public String toXmlString() throws TransformerException {
        if (doc == null) {
            return null;
        }
        final DOMSource domSource = new DOMSource(doc);
        final StringWriter writer = new StringWriter();
        final StreamResult result = new StreamResult(writer);
        final TransformerFactory tf = TransformerFactory.newInstance();
        tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        final Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        transformer.transform(domSource, result);

        return writer.toString();
    }
1112354
@Override
    public String execute(EditXmlInputs inputs) throws Exception {
        Document doc = XmlUtils.createDocument(inputs.getXml(), inputs.getFilePath(), inputs.getParsingFeatures());
        NodeList nodeList = XmlUtils.readNode(doc, inputs.getXpath1(), XmlUtils.getNamespaceContext(inputs.getXml(), inputs.getFilePath()));
        Node childNode = null;
        Node node;

        if (Constants.Inputs.TYPE_ELEM.equals(inputs.getType())) {
            childNode = XmlUtils.stringToNode(inputs.getValue(), doc.getXmlEncoding(), inputs.getParsingFeatures());
        }

        for (int i = 0; i < nodeList.getLength(); i++) {
            node = nodeList.item(i);

            if (Constants.Inputs.TYPE_ELEM.equals(inputs.getType())) {
                childNode = doc.importNode(childNode, true);
                node.setTextContent(Constants.Inputs.EMPTY_STRING);
                node.appendChild(childNode);
            } else if (Constants.Inputs.TYPE_TEXT.equals(inputs.getType())) {
                node.setTextContent(inputs.getValue());
            } else if (Constants.Inputs.TYPE_ATTR.equals(inputs.getType())) {
                String attribute = ((Element) node).getAttribute(inputs.getName());
                if ((attribute != null) && (!StringUtils.isEmpty(attribute))) {
                    ((Element) node).setAttribute(inputs.getName(), inputs.getValue());
                }
            }
        }
        return DocumentUtils.documentToString(doc);
    }
1145965
protected void writeElementContent(String text, Writer out) throws IOException {
		// esccape '<', '&', ']]>', <32 if necessary
		int pos = 0;
		for (int i = 0; i < text.length(); i++) {
			// TODO: check if doing char[] text.getChars() would be faster than
			// getCharAt(i) ...
			char ch = text.charAt(i);
			if (ch == ']') {
				if (seenBracket) {
					seenBracketBracket = true;
				} else {
					seenBracket = true;
				}
			} else {
				if (ch == '&') {
					if (i > pos)
						out.write(text.substring(pos, i));
					out.write("&amp;");
					pos = i + 1;
				} else if (ch == '<') {
					if (i > pos)
						out.write(text.substring(pos, i));
					out.write("&lt;");
					pos = i + 1;
				} else if (seenBracketBracket && ch == '>') {
					if (i > pos)
						out.write(text.substring(pos, i));
					out.write("&gt;");
					pos = i + 1;
				} else if (ch < 32) {
					// in XML 1.0 only legal character are #x9 | #xA | #xD
					if (ch == 9 || ch == 10 || ch == 13) {
						// pass through

						// } else if(ch == 13) { //escape
						// if(i > pos) out.write(text.substring(pos, i));
						// out.write("&#");
						// out.write(Integer.toString(ch));
						// out.write(';');
						// pos = i + 1;
					} else {
						if (TRACE_ESCAPING)
							System.err.println(getClass().getName() + " DEBUG TEXT value.len=" + text.length() + " " + printable(text));
						throw new IllegalStateException("character " + Integer.toString(ch) + " is not allowed in output" + getLocation() + " (text value=" + printable(text) + ")");
						// in XML 1.1 legal are [#x1-#xD7FF]
						// if(ch > 0) {
						// if(i > pos) out.write(text.substring(pos, i));
						// out.write("&#");
						// out.write(Integer.toString(ch));
						// out.write(';');
						// pos = i + 1;
						// } else {
						// throw new IllegalStateException(
						// "character zero is not allowed in XML 1.1
						// output"+getLocation());
						// }
					}
				}
				if (seenBracket) {
					seenBracketBracket = seenBracket = false;
				}

			}
		}
		if (pos > 0) {
			out.write(text.substring(pos));
		} else {
			out.write(text); // this is shortcut to the most common case
		}

	}