将String类型的XML转换为XML文档

@param xmlStr XML字符串
@return XML文档
352164
public static Document parseXml(String xmlStr) {
		if (StrUtil.isBlank(xmlStr)) {
			throw new IllegalArgumentException("XML content string is empty !");
		}
		xmlStr = cleanInvalid(xmlStr);
		return readXML(new InputSource(StrUtil.getReader(xmlStr)));
	}
229002
public static String toXml(Object root) {
		Class clazz = ClassUtil.unwrapCglib(root);
		return toXml(root, clazz, null);
	}
1303689
public String toXML() {
        Error error = getError();

        if (error != null) {
            return error.toXML();
        }

        StringWriter sw = new StringWriter();
        String xml = "";

        try {
            JAXBContext context = JAXBContext.newInstance(this.getClass());
            Marshaller marshaller = context.createMarshaller();

            marshaller.marshal(this, sw);
            xml = sw.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xml;
    }
1008826
def to_xml_string(str = '')
      str << '<xdr:twoCellAnchor>'
      str << '<xdr:from>'
      from.to_xml_string str
      str << '</xdr:from>'
      str << '<xdr:to>'
      to.to_xml_string str
      str << '</xdr:to>'
      object.to_xml_string(str)
      str << '<xdr:clientData/>'
      str << '</xdr:twoCellAnchor>'
    end
688063
def parse_string(self, xmlstr, initialize=True):
        
        try:
            domtree = minidom.parseString(xmlstr)
        except xml.parsers.expat.ExpatError, e:
            raise ManifestXMLParseError(e)
        self.load_dom(domtree, initialize)
480172
public String toXml(Object root, String encoding) {
        try {
            StringWriter writer = new StringWriter();
            createMarshaller(encoding).marshal(root, writer);
            return writer.toString();
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
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();
   }
314589
def String(self, str):
        
        ret = libxml2mod.xmlTextReaderConstString(self._o, str)
        return ret
434381
private static String escapeXml (String nonEscapedXmlStr) {
        StringBuilder escapedXML = new StringBuilder();
        for (int i = 0; i < nonEscapedXmlStr.length(); i++) {
            char c = nonEscapedXmlStr.charAt(i);
            switch (c) {
                case '<':
                    escapedXML.append("&lt;");
                    break;
                case '>':
                    escapedXML.append("&gt;");
                    break;
                case '\"':
                    escapedXML.append("&quot;");
                    break;
                case '&':
                    escapedXML.append("&amp;");
                    break;
                case '\'':
                    escapedXML.append("&apos;");
                    break;
                default:
                    if (c > 0x7e) {
                        escapedXML.append("&#" + ((int) c) + ";");
                    } else {
                        escapedXML.append(c);
                    }
            }
        }
        return escapedXML.toString();
    }
392347
public static Map<String, Object> xmlToMap(String xmlStr) {
		return xmlToMap(xmlStr, new HashMap<String, Object>());
	}
1056649
def to_xml_string(str = "")
      str << ('<c:' << @tag_name.to_s << '>')
      str << ('<c:formatCode>' << format_code.to_s << '</c:formatCode>')
      str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
      @pt.each_with_index do |num_val, index|
        num_val.to_xml_string index, str
      end
      str << ('</c:' << @tag_name.to_s << '>')
    end
1323640
static String toXmlString(Node node) {
        try {
            Transformer transformer = getTF().newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(node);
            transformer.transform(source, result);
            return sw.toString();
        } catch (Exception e) {
            throw wrap(e);
        }
    }
1041821
def to_xml_string(str = '')
      str << '<c:scaling>'
      str << ('<c:logBase val="' << @logBase.to_s << '"/>') unless @logBase.nil?
      str << ('<c:orientation val="' << @orientation.to_s << '"/>') unless @orientation.nil?
      str << ('<c:min val="' << @min.to_s << '"/>') unless @min.nil?
      str << ('<c:max val="' << @max.to_s << '"/>') unless @max.nil?
      str << '</c:scaling>'
    end
599416
public static String xmlToString(File file) throws AlipayApiException {
        Element root = getRootElementFromFile(file);
        return nodeToString(root);
    }
954273
def to_xml_string(str = '')
      super(str) do
        str << '<c:scatterChart>'
        str << ('<c:scatterStyle val="' << scatter_style.to_s << '"/>')
        str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
        @series.each { |ser| ser.to_xml_string(str) }
        d_lbls.to_xml_string(str) if @d_lbls
        axes.to_xml_string(str, :ids => true)
        str << '</c:scatterChart>'
        axes.to_xml_string(str)
      end
      str
    end
1042177
public static String toStr(Document doc, String charset, boolean isPretty) {
		final StringWriter writer = StrUtil.getWriter();
		try {
			write(doc, writer, charset, isPretty ? INDENT_DEFAULT : 0);
		} catch (Exception e) {
			throw new UtilException(e, "Trans xml document to string error!");
		}
		return writer.toString();
	}
968275
public String getAsXMLString() {
        // Create a string XML representation:
        String rewardString = null;
        try {
            rewardString = SchemaHelper.serialiseObject(this.getAsReward(), Reward.class);
        } catch (JAXBException e) {
            System.out.println("Caught reward serialization exception: " + e);
        }
        return rewardString;
    }