Extracts the tag from an XML element.

@param out
The StringBuilder to write to.
@param in
Input StringBuilder.
348576
public final static void getXMLTag(final StringBuilder out, final StringBuilder in)
    {
        int pos = 1;
        if (in.charAt(1) == '/')
        {
            pos++;
        }
        while (Character.isLetterOrDigit(in.charAt(pos)))
        {
            out.append(in.charAt(pos++));
        }
    }
931082
private void init(InputSource is) throws TagLibException {
	// print.dumpStack();
	try {
	    xmlReader = XMLUtil.createXMLReader();
	    xmlReader.setContentHandler(this);
	    xmlReader.setErrorHandler(this);
	    xmlReader.setEntityResolver(new TagLibEntityResolver());
	    xmlReader.parse(is);
	}
	catch (IOException e) {

	    // String fileName=is.getSystemId();
	    // String message="IOException: ";
	    // if(fileName!=null) message+="In File ["+fileName+"], ";
	    throw new TagLibException(e);
	}
	catch (SAXException e) {
	    // String fileName=is.getSystemId();
	    // String message="SAXException: ";
	    // if(fileName!=null) message+="In File ["+fileName+"], ";
	    throw new TagLibException(e);
	}

    }
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);
        }
    }
854476
protected static final void toXML(StringBuilder out, int indent, boolean insertMeta, Tree node) {
		String name = node.get("_name", node.isPrimitive() ? "item" : node.getName());

		// Start XML element
		addSpaces(out, indent);
		out.append('<');
		String elementName;
		if (name == null || name.isEmpty()) {
			elementName = node.get("_name", node.getParent() == null ? "xml" : "item");
		} else {
			elementName = name;
		}
		out.append(elementName);

		// Write attributes
		for (Tree attr : node) {
			String attrName = attr.getName();
			if (!attrName.startsWith("@")) {
				continue;
			}
			out.append(' ');
			out.append(attrName.substring(1));
			out.append(EQUALS);
			writeAttribute(out, attr.asString());
			out.append('\"');
		}

		// End of XML element
		out.append('>');
		if (indent > -1) {
			out.append(CR_LF);
		}

		// Insert metadata
		if (insertMeta) {
			Tree meta = node.getMeta(false);
			if (meta != null && !meta.isEmpty()) {
				toXML(out, indent > -1 ? 2 : -1, false, meta);
			}
		}

		// Properties
		int len = out.length();
		String text = null;
		for (Tree child : node) {
			String childName = child.getName();
			if (childName.isEmpty() || node.isEnumeration()) {
				childName = "item";
			} else {
				if (childName.startsWith("@") || "_name".equals(childName)) {
					continue;
				}
				if ("_text".equals(childName)) {
					text = child.asString();
					continue;
				}
			}
			
			// BASE64
			if (!child.isPrimitive()) {
				continue;
			}
			if (indent > -1) {
				addSpaces(out, indent + 2);
			}
			out.append('<');
			out.append(childName);
			out.append('>');
			writeXMLContent(out, String.valueOf(child.asString()));
			out.append(BEGIN_END_TAG);
			out.append(childName);
			out.append('>');
			if (indent > -1) {
				out.append(CR_LF);
			}
		}
		if (text == null && node.isPrimitive()) {
			text = node.asString();
		}
		if (text == null) {

			// Write items of array
			Tree items = node.get("_items");

			if (items != null) {
				addChildren(out, indent, items, false);
			} else {
				addChildren(out, indent, node, true);
			}

			// Formatting
			if (indent > -1) {
				if (out.length() == len) {
					out.setLength(len - 2);
				} else {
					addSpaces(out, indent);
				}
			}
		} else {

			// Formatting
			if (indent > -1) {
				out.setLength(len - 2);
			}

			// Text content
			writeXMLContent(out, text.trim());
		}

		// Close element
		out.append(BEGIN_END_TAG);
		out.append(elementName);
		out.append('>');
		if (indent > 0) {
			out.append(CR_LF);
		}
	}
783757
public void writeXml(OutputStream out) throws IOException {
        Properties properties = getProps();
        try {
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            Element conf = doc.createElement("configuration");
            doc.appendChild(conf);
            conf.appendChild(doc.createTextNode("\n"));
            for (Enumeration e = properties.keys(); e.hasMoreElements();) {
                String name = (String) e.nextElement();
                Object object = properties.get(name);
                String value;
                if (object instanceof String) {
                    value = (String) object;
                } else {
                    continue;
                }
                Element propNode = doc.createElement("property");
                conf.appendChild(propNode);

                Element nameNode = doc.createElement("name");
                nameNode.appendChild(doc.createTextNode(name));
                propNode.appendChild(nameNode);

                Element valueNode = doc.createElement("value");
                valueNode.appendChild(doc.createTextNode(value));
                propNode.appendChild(valueNode);

                conf.appendChild(doc.createTextNode("\n"));
            }

            DOMSource source = new DOMSource(doc);
            StreamResult result = new StreamResult(out);
            TransformerFactory transFactory = TransformerFactory.newInstance();
            Transformer transformer = transFactory.newTransformer();
            transformer.transform(source, result);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
116096
@Nonnull
  public static String getXMLTag (final String in)
  {
    final StringBuilder aSB = new StringBuilder ();
    int pos = 1;
    if (in.charAt (1) == '/')
      pos++;
    while (Character.isLetterOrDigit (in.charAt (pos)))
      aSB.append (in.charAt (pos++));
    return aSB.toString ().toLowerCase (Locale.US);
  }
424278
public static void convertDOMToXML(Node doc, Writer out)
    {
        try {
            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            DOMSource source = new DOMSource(doc);

            StreamResult result = new StreamResult(out);
            transformer.transform(source, result);
        } catch (TransformerConfigurationException tce) {
            // Error generated by the parser
            tce.printStackTrace();
        } catch (TransformerException te) {
            // Error generated by the parser
            te.printStackTrace();
        }
    }
1088805
public static Element stringToElement(String xml) throws Exception {
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document d = builder.parse(bais);
      bais.close();
      return d.getDocumentElement();
   }
86201
private void readTag() throws XMLException, IOException {
		try {
			char c;
			if ((c = stream.read()) == '!') {
				readTagExclamation();
			} else if (c == '?') {
				readProcessingInstruction();
			} else if (c == '/') {
				readEndTag();
			} else if (isNameStartChar(c)) {
				readStartTag(c);
			} else {
				throw new XMLException(getPosition(), "Unexpected character", Character.valueOf(c));
			}
		} catch (EOFException e) {
			throw new XMLException(getPosition(), new LocalizableString("lc.xml.error", "Unexpected end"),
					new LocalizableString("lc.xml.error", "in XML document"));
		}
	}
17658
public void parseStreamPrintHtml(PrintWriter out, InputStream streamIn)
    {
        XMLParser parser = ((BaseParserScreen)this.getScreenField()).getXMLParser();
        if (parser != null)
        {
            parser.printHtmlData(out, streamIn);
            parser.free();
            parser = null;
        }
        else
        {
            Utility.transferURLStream(null, null, new InputStreamReader(streamIn), out);
        }
    }
221703
public static XElement parseXMLActiveFragment(XMLStreamReader in) throws XMLStreamException {
        XElement node = null;
        XElement root = null;
        final StringBuilder emptyBuilder = new StringBuilder();
        StringBuilder b = null;
        Deque<StringBuilder> stack = new LinkedList<>();

        int type = in.getEventType();
        
        for (;;) {
            switch(type) {
            case XMLStreamConstants.START_ELEMENT:
                if (b != null) {
                    stack.push(b);
                    b = null;
                } else {
                    stack.push(emptyBuilder);
                }
                XElement n = new XElement(in.getName().getLocalPart());
                n.parent = node;
                int attCount = in.getAttributeCount();
                if (attCount > 0) {
                    for (int i = 0; i < attCount; i++) {
                        n.set(in.getAttributeLocalName(i), in.getAttributeValue(i));
                    }
                }
                if (node != null) {
                    node.add(n);
                }
                node = n;
                if (root == null) {
                    root = n;
                }
                break;
            case XMLStreamConstants.CDATA:
            case XMLStreamConstants.CHARACTERS:
                if (node != null && !in.isWhiteSpace()) {
                    if (b == null) {
                        b = new StringBuilder();
                    }
                    b.append(in.getText());
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                if (node != null) {
                    if (b != null) {
                        node.content = b.toString();
                    }
                    node = node.parent;
                }
                b = stack.pop();
                if (b == emptyBuilder) {
                    b = null;
                }
                if (stack.isEmpty()) {
                    return root;
                }
                break;
            default:
                // ignore others.
            }
            
            if (in.hasNext()) {
                type = in.next();
            } else {
                break;
            }
        }
        return root;
    }
190848
public static XElement parseXML(XMLStreamReader in) throws XMLStreamException {
        XElement root = parseXMLFragment(in);
        in.close();
        return root;
    }
219436
public void convert(org.jsoup.nodes.Document in, Document out) {
        if (!StringUtil.isBlank(in.location()))
            out.setDocumentURI(in.location());

        org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
        NodeTraversor.traverse(new W3CBuilder(out), rootEl);
    }
217747
public void readTags(InputStream tagsXML)
    {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try
        {
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(tagsXML, new TagsSaxHandler(this));
        }
        catch (ParserConfigurationException | SAXException | IOException ex)
        {
            throw new RuntimeException("Failed parsing the tags definition: " + ex.getMessage(), ex);
        }
    }
536866
private static void appendTag(String tag, StringBuilder buffer) {
        if (buffer.length() != 0) {
            buffer.append(UNDERSCORE);
        }

        buffer.append(tag);
    }
1331670
protected Text extractText(Element fromElement) {
        fromElement.normalize();
        NodeList fromNodeList = fromElement.getChildNodes(); 
        Node currentNode;
        for (int i=0; i < fromNodeList.getLength(); ++i) {
            currentNode = fromNodeList.item(i);
            if (currentNode.getNodeType() == Node.TEXT_NODE) {
                return (Text) currentNode;
            }
        }
        return null;
    }
1312310
public static void copy(String in, Writer out) throws IOException {
        assert in != null : "No input String specified";
        assert out != null : "No output Writer specified";

        try {
            out.write(in);
        } finally {
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }