Get the XML snippet (i.e. not a complete XML document) for the given rules.
@see #getXmlStart
@see #getXmlEnd()
770011
public String ruleMatchesToXmlSnippet(List<RuleMatch> ruleMatches, String text, int contextSize) {
    StringBuilder xml = new StringBuilder(CAPACITY);
    //
    // IMPORTANT: people rely on this format, don't change it!
    //
    ContextTools contextTools = new ContextTools();
    contextTools.setEscapeHtml(false);
    contextTools.setContextSize(contextSize);
    String startMarker = "__languagetool_start_marker";
    contextTools.setErrorMarkerStart(startMarker);
    contextTools.setErrorMarkerEnd("");

    for (RuleMatch match : ruleMatches) {
      String subId = "";
      if (match.getRule() instanceof AbstractPatternRule) {
        AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
        if (pRule.getSubId() != null) {
          subId = " subId=\"" + escapeXMLForAPIOutput(pRule.getSubId()) + "\" ";
        }
      }
      xml.append("<error fromy=\"").append(match.getLine()).append('"')
              .append(" fromx=\"").append(match.getColumn() - 1).append('"')
              .append(" toy=\"").append(match.getEndLine()).append('"')
              .append(" tox=\"").append(match.getEndColumn() - 1).append('"')
              .append(" ruleId=\"").append(match.getRule().getId()).append('"');
      xml.append(subId);
      String msg = match.getMessage().replaceAll("</?suggestion>", "'");
      xml.append(" msg=\"").append(escapeXMLForAPIOutput(msg)).append('"');
      if (!match.getShortMessage().isEmpty()) {
        xml.append(" shortmsg=\"").append(escapeXMLForAPIOutput(match.getShortMessage())).append('"');
      }
      xml.append(" replacements=\"").append(escapeXMLForAPIOutput(
              String.join("#", match.getSuggestedReplacements()))).append('"');
      String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
      // get position of error in context and remove artificial marker again:
      int contextOffset = context.indexOf(startMarker);
      context = context.replaceFirst(startMarker, "");
      context = context.replaceAll("[\n\r]", " ");
      xml.append(" context=\"").append(escapeForXmlAttribute(context)).append('"')
              .append(" contextoffset=\"").append(contextOffset).append('"')
              .append(" offset=\"").append(match.getFromPos()).append('"')
              .append(" errorlength=\"").append(match.getToPos() - match.getFromPos()).append('"');
      if (match.getRule().getUrl() != null) {
        xml.append(" url=\"").append(escapeXMLForAPIOutput(match.getRule().getUrl().toString())).append('"');
      }
      Category category = match.getRule().getCategory();
      if (category != null) {
        xml.append(" category=\"").append(escapeXMLForAPIOutput(category.getName())).append('"');
        CategoryId id = category.getId();
        if (id != null) {
          xml.append(" categoryid=\"").append(escapeXMLForAPIOutput(id.toString())).append('"');
        }
      }
      ITSIssueType type = match.getRule().getLocQualityIssueType();
      if (type != null) {
        xml.append(" locqualityissuetype=\"").append(escapeXMLForAPIOutput(type.toString())).append('"');
      }
      xml.append("/>\n");
    }
    return xml.toString();
  }
1126321
public static DocumentBuilder getXmlParser() {
    DocumentBuilder db = null;
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setValidating(false);

      //Disable DTD loading and validation
      //See http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
      dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
      dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

      db = dbf.newDocumentBuilder();
      db.setErrorHandler(new SAXErrorHandler());

    } catch (ParserConfigurationException e) {
      System.err.printf("%s: Unable to create XML parser\n", XMLUtils.class.getName());
      e.printStackTrace();

    } catch(UnsupportedOperationException e) {
      System.err.printf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName());
      e.printStackTrace();
    }

    return db;
  }
57001
private XmlNode pullXmlNode() {
        // read from queue
        if(! nodeQueue.isEmpty()) {
            return nodeQueue.poll();
        }

        // read from stream
        try {
            while(reader.hasNext()) {
                int event = reader.next();
                switch(event) {
                    case XMLStreamConstants.START_ELEMENT:
                        return new XmlStartElement(reader.getLocalName(), getAttributes(reader));
                    case XMLStreamConstants.CHARACTERS:
                        // capture XML?
                        String text = filterWhitespace(reader.getText());
                        if(text.length() > 0) {
                            return new XmlContent(text);
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        return new XmlEndElement(reader.getLocalName());
                    default:
                        // do nothing
                }
            }
        } catch (XMLStreamException e) {
            throw new XmlReaderException(e);
        }
        // nothing to return
        return null;
    }
411147
protected function getCombinedXML($innerXML)
    {
        // Determine start and end tags from configuration:
        $start = $this->wrappingTag;
        $tmp = explode(' ', $start);
        $end = '</' . str_replace(['<', '>'], '', $tmp[0]) . '>';

        // Assemble the document:
        return $start . $innerXML . $end;
    }
793224
private SAXBuilder getSAXBuilder() {
    final LineNumberSAXBuilder builder = new LineNumberSAXBuilder();

    // this parser configuration will use an xsd schema for validation
    // if one is specified in the xml itself and if that xsd can be found
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);
    builder.setFeature("http://apache.org/xml/features/validation/dynamic", true);
    builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

    builder.setErrorHandler(new ErrorHandler() {

      /** {@inheritDoc} */
      @Override
      public void error(SAXParseException exception) throws SAXParseException {
        throw exception;
      }

      /** {@inheritDoc} */
      @Override
      public void fatalError(SAXParseException exception) throws SAXParseException {
        throw exception;
      }

      /** {@inheritDoc} */
      @Override
      public void warning(SAXParseException exception) throws SAXParseException {
        if (treatWarningsAsErrors) {
          throw exception;
        } else {
          parseWarnings.add(new ParseWarning(exception.getMessage(), exception.getLineNumber()));
        }
      }

    });
    return builder;
  }
391319
private Node getNode(boolean bDataRoot)
    {
        if (m_data == null)
        {
            DocumentBuilder db = Util.getDocumentBuilder();
            synchronized (db)
            {
                m_data = (Node)db.newDocument();
                String rootTag = ROOT_TAG;
                if (this.getMessageDataDesc(null) != null)
                	if (this.getMessageDataDesc(null).getKey() != null)
                		rootTag = this.getMessageDataDesc(null).getKey();
                ((Document)m_data).appendChild(((Document)m_data).createElement(rootTag));
            }
        }
        if (bDataRoot)
        	if (m_data instanceof Document)
        		return ((Document)m_data).getDocumentElement();
        return (Node)m_data;
    }
512011
public static Node getMainElement(Document xml) {
        // Try to get main mws:expr first
        NodeList expr = xml.getElementsByTagName("mws:expr");
        if (expr.getLength() > 0) {
            return new NonWhitespaceNodeList(expr).item(0);
        }
        // if that fails try to get content MathML from an annotation tag
        Node node = getContentMathMLNode(xml);
        if (node != null) {
            return node;
        }
        // if that fails too interprete content of first semantic element as content MathML
        expr = xml.getElementsByTagNameNS("*", "semantics");
        if (expr.getLength() > 0) {
            return new NonWhitespaceNodeList(expr).item(0);
        }
        // if that fails too interprete content of root MathML element as content MathML
        expr = xml.getElementsByTagName("math");
        if (expr.getLength() > 0) {
            return new NonWhitespaceNodeList(expr).item(0);
        }

        return null;
    }
1296319
public String toXML()
    {
        String eol = SystemUtils.LINE_SEPARATOR;
        StringBuffer buf = new StringBuffer();

        // write all ClassDescriptors
        Iterator i = this.iterator();
        while (i.hasNext())
        {
            buf.append(((XmlCapable) i.next()).toXML() + eol);
        }
        return buf.toString();
    }
776476
public static Node getElementB(Node node, XPathExpression xPath) throws XPathExpressionException {
        return getElementsB(node, xPath).item(0);
    }
992071
public int getSnippetBegin() {
    if (Cooccurrence_Type.featOkTst && ((Cooccurrence_Type)jcasType).casFeat_snippetBegin == null)
      jcasType.jcas.throwFeatMissing("snippetBegin", "ch.epfl.bbp.uima.types.Cooccurrence");
    return jcasType.ll_cas.ll_getIntValue(addr, ((Cooccurrence_Type)jcasType).casFeatCode_snippetBegin);}
342475
public function outerXml()
    {
        $attributes = '';
        foreach ($this->getAttributes() as $name => $value) {
            if ($value === null) {
                // Self-closing attribute format.
                $attributes .= " $name";
            } else {
                // Full attribute format.
                $value = addslashes($value);
                $attributes .= " $name=\"$value\"";
            }
        }

        // Self-closing element format.
        if ($this->getText() === null && count($this->getChildren()) == 0) {
            return "<{$this->getName()}$attributes/>";
        }

        // Full element format.
        return "<{$this->getName()}$attributes>{$this->innerXml()}</{$this->getName()}>";
    }
1037378
private String getCodeSnippetHtml(Throwable cause) {
        StringBuilder codeSnippet = new StringBuilder();
        BufferedReader reader = null;
        
        try {
            if (cause instanceof CitrusRuntimeException) {
                CitrusRuntimeException ex = (CitrusRuntimeException) cause;
                if (!ex.getFailureStack().isEmpty()) {
                    FailureStackElement stackElement = ex.getFailureStack().pop();
                    if (stackElement.getLineNumberStart() > 0) {
                        reader = new BufferedReader(new FileReader(
                                new ClassPathResource(stackElement.getTestFilePath() + ".xml").getFile()));
                        
                        codeSnippet.append("<div class=\"code-snippet\">");
                        codeSnippet.append("<h2 class=\"code-title\">" + stackElement.getTestFilePath() + ".xml</h2>");
                        
                        String line;
                        String codeStyle;
                        int lineIndex = 1;
                        int snippetOffset = 5;
                        while ((line = reader.readLine()) != null) {
                            if (lineIndex >= stackElement.getLineNumberStart() - snippetOffset && 
                                    lineIndex < stackElement.getLineNumberStart() || 
                                    lineIndex > stackElement.getLineNumberEnd() && 
                                    lineIndex <= stackElement.getLineNumberEnd() + snippetOffset) {
                                codeStyle = "code";
                            } else if (lineIndex >= stackElement.getLineNumberStart() && 
                                    lineIndex <= stackElement.getLineNumberEnd()) {
                                codeStyle = "code-failed";
                            } else {
                                codeStyle = "";
                            }
                            
                            if (StringUtils.hasText(codeStyle)) {
                                codeSnippet.append("<pre class=\"" + codeStyle +"\"><span class=\"line-number\">" + lineIndex + ":</span>" + 
                                        line.replaceAll(">", "&gt;").replaceAll("<", "&lt;") + "</pre>");
                            }
                            
                            lineIndex++;
                            
                        }
                        
                        codeSnippet.append("</div>");
                    }
                }
            }
        } catch (IOException e) {
            log.error("Failed to construct HTML code snippet", e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    log.warn("Failed to close test file", e);
                }
            }
        }
        
        return codeSnippet.toString();
    }
1307313
public function getInnerXml()
	{
		if ( is_null( $this->domNode ) ) return null;
		$owner = $this->domNode instanceof \DOMDocument ? $this->domNode : $this->domNode->ownerDocument;
		$xml = $owner->saveXml( $this->domNode, LIBXML_NOEMPTYTAG );
		$xml = ltrim( preg_replace( "/^<\?xml.*\?>/", "", $xml ) );
		$xml = ltrim( preg_replace( "/^<!DOCTYPE[^>[]*(\[[^]]*\])?>/s", "", $xml ) );
		return $xml;
	}
671222
public function getXMLContent()
    {
        if ($this->xmlContent === null) {
            try {
                if (($content = $this->content) === '') {
                    return $this->xmlContent = false;
                }

                $errors = libxml_use_internal_errors(true);
                $this->xmlContent = new SimpleXMLElement($content);
                libxml_use_internal_errors($errors);
            } catch (Exception $exception) {
                return $this->xmlContent = false;
            }
        }

        return $this->xmlContent;
    }
798023
public String getXML()
    {
        if (this.getConvertToNative() != null)
        {
            String strXML = this.getConvertToNative().getXML();
            if (strXML != null)
                return strXML;
        }
        return null;
    }
644115
public boolean nextInnerElement(ElementContext parent) throws XMLException, IOException {
		if (event.context.isEmpty()) return false;
		if (Type.START_ELEMENT.equals(event.type) && event.context.getFirst() == parent && event.isClosed)
			return false; // we are one the opening tag of the parent, and it is closed, so it has no content
		if (Type.END_ELEMENT.equals(event.type) && event.context.getFirst() == parent)
			return false;
		try {
			do {
				next();
				if (Type.END_ELEMENT.equals(event.type)) {
					if (event.context.getFirst() == parent)
						return false;
				}
				if (Type.START_ELEMENT.equals(event.type)) {
					if (event.context.size() > 1 && event.context.get(1) == parent)
						return true;
				}
			} while (true);
		} catch (EOFException e) {
			return false;
		}
	}
230705
public function xml_start(){
		if (isset($_GET[$this->parent_name])) {
			return "<data parent='".$_GET[$this->parent_name].$this->render->get_postfix()."'>";
		} else {
			return "<data parent='0'>";
		}
	}