Here you can find the source of strToXML(final Document doc, final String namespaceURI, final String qname, final String str)
Parameter | Description |
---|---|
doc | XML Document in which to build the XML element |
namespaceURI | the namespace URI |
qname | top level qualified XML node name in XML representation |
str | the string |
public final static Element strToXML(final Document doc, final String namespaceURI, final String qname, final String str)
//package com.java2s; /**/* w w w .j a v a 2 s .c o m*/ * The contents of this file are subject to the Regenstrief Public License * Version 1.0 (the "License"); you may not use this file except in compliance with the License. * Please contact Regenstrief Institute if you would like to obtain a copy of the license. * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) Regenstrief Institute. All Rights Reserved. */ import org.w3c.dom.*; public class Main { /** * returns XML representation of a string, with specified XML node name * * @param doc XML Document in which to build the XML element * @param nodename top level XML node name in XML representation * @param str the string * @return XML representation of the string, with specified XML node name **/ public final static Element strToXML(final Document doc, final String nodename, final String str) { return strToXML(doc, null, nodename, str); } /** * returns XML representation of a string, with specified XML node name * * @param doc XML Document in which to build the XML element * @param namespaceURI the namespace URI * @param qname top level qualified XML node name in XML representation * @param str the string * @return XML representation of the string, with specified XML node name **/ public final static Element strToXML(final Document doc, final String namespaceURI, final String qname, final String str) { if (str == null /*|| str.length() == 0*/) { return null; } final Element xml = doc.createElementNS(namespaceURI, qname); xml.appendChild(doc.createTextNode(str)); return xml; } /** * Appends a child to the given xml Node * * @param xml the parent Node * @param child the child Node to append to parent **/ public final static void appendChild(final Node xml, final Node child) { if ((xml == null) || (child == null)) { return; } xml.appendChild(child); } }