Sorts the incoming xml.

@param originalXml the xml that should be sorted.
@return the sorted xml
11635
private String sortXml(final String originalXml) {

        xmlProcessingInstructionParser.scanForIgnoredSections(originalXml);
        String xml = xmlProcessingInstructionParser.replaceIgnoredSections();

        insertXmlInXmlProcessor(xml, () -> "Could not sort " + pomFile.getAbsolutePath() + " content: ");
        xmlProcessor.sortXml();
        Document newDocument = xmlProcessor.getNewDocument();

        String sortedXml = xmlOutputGenerator.getSortedXml(newDocument);
        if (xmlProcessingInstructionParser.existsIgnoredSections()) {
            sortedXml = xmlProcessingInstructionParser.revertIgnoredSections(sortedXml);
        }
        return sortedXml;
    }
999928
public ElemTemplateElement appendChild(ElemTemplateElement newChild)
  {

    int type = ((ElemTemplateElement) newChild).getXSLToken();

    if (Constants.ELEMNAME_SORT == type)
    {
      setSortElem((ElemSort) newChild);

      return newChild;
    }
    else
      return super.appendChild(newChild);
  }
1304269
func SortXML(r io.Reader) string {
	var buf bytes.Buffer
	d := xml.NewDecoder(r)
	root, _ := xmlutil.XMLToStruct(d, nil)
	e := xml.NewEncoder(&buf)
	xmlutil.StructToXML(e, root, true)
	return buf.String()
}
761950
public String xmlToThrift(String name) {
    name = name.replace("-custom.xml", "");
    name = name.replace(".xml", "");
    name = name.replace("-", "_");
    return name;
  }
1246866
public void scan(String originalXml) {
        Matcher matcher = INSTRUCTION_PATTERN.matcher(originalXml);
        while (matcher.find()) {
            scanOneInstruction(matcher.group(1));
            containsIgnoredSections = true;
        }
        if (expectedNextInstruction != IGNORE) {
            addError(String.format("Xml processing instructions for sortpom was not properly terminated. Every <?sortpom %s?> must be followed with <?sortpom %s?>",
                    IGNORE, RESUME));
        }
    }
1283854
private String getDefaultSortOrderXml() throws IOException {
        CheckedSupplier<InputStream, IOException> createStreamFunc = () -> {
            if (customSortOrderFile != null) {
                UrlWrapper urlWrapper = new UrlWrapper(customSortOrderFile);
                if (urlWrapper.isUrl()) {
                    return urlWrapper.openStream();
                } else {
                    return openCustomSortOrderFile();
                }
            } else if (predefinedSortOrder != null) {
                return getPredefinedSortOrder(predefinedSortOrder);
            }
            return getPredefinedSortOrder(DEFAULT_SORT_ORDER_FILENAME);
        };

        try (InputStream inputStream = createStreamFunc.get()) {
            return IOUtils.toString(inputStream, encoding);
        }
    }
197304
public boolean setXML(String strXML)
    {
        Document doc = Util.convertXMLToDOM(strXML);
        return this.setDOM(doc);
    }
739406
public static Document toDocument(String xml) throws SAXException {
		try {
			return toDocument(new StringReader(xml));
		} catch (IOException e) {
			//reading from string
			throw new RuntimeException(e);
		}
	}
138971
public DTMIterator sortNodes(
          XPathContext xctxt, Vector keys, DTMIterator sourceNodes)
            throws TransformerException
  {

    NodeSorter sorter = new NodeSorter(xctxt);
    sourceNodes.setShouldCacheNodes(true);
    sourceNodes.runTo(-1);
    xctxt.pushContextNodeList(sourceNodes);

    try
    {
      sorter.sort(sourceNodes, keys, xctxt);
      sourceNodes.setCurrentPos(0);
    }
    finally
    {
      xctxt.popContextNodeList();
    }

    return sourceNodes;
  }
261092
public CmsFile correctXmlStructure(CmsObject cms) throws CmsXmlException {

        // apply XSD schema translation
        Attribute schema = m_document.getRootElement().attribute(
            I_CmsXmlSchemaType.XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION);
        if (schema != null) {
            String schemaLocation = schema.getValue();
            String translatedSchema = OpenCms.getResourceManager().getXsdTranslator().translateResource(schemaLocation);
            if (!schemaLocation.equals(translatedSchema)) {
                schema.setValue(translatedSchema);
            }
        }
        updateLocaleNodeSorting();

        // iterate over all locales
        Iterator<Locale> i = m_locales.iterator();
        while (i.hasNext()) {
            Locale locale = i.next();
            List<String> names = getNames(locale);
            List<I_CmsXmlContentValue> validValues = new ArrayList<I_CmsXmlContentValue>();

            // iterate over all nodes per language
            Iterator<String> j = names.iterator();
            while (j.hasNext()) {

                // this step is required for values that need a processing of their content
                // an example for this is the HTML value that does link replacement
                String name = j.next();
                I_CmsXmlContentValue value = getValue(name, locale);
                if (value.isSimpleType()) {
                    String content = value.getStringValue(cms);
                    value.setStringValue(cms, content);
                }

                // save valid elements for later check
                validValues.add(value);
            }

            if (isAutoCorrectionEnabled()) {
                // full correction of XML
                if (validValues.size() < 1) {
                    // no valid element was in the content
                    if (hasLocale(locale)) {
                        // remove the old locale entirely, as there was no valid element
                        removeLocale(locale);
                    }
                    // add a new default locale, this will also generate the default XML as required
                    addLocale(cms, locale);
                } else {
                    // there is at least one valid element in the content

                    List<Element> roots = new ArrayList<Element>();
                    List<CmsXmlContentDefinition> rootCds = new ArrayList<CmsXmlContentDefinition>();
                    List<Element> validElements = new ArrayList<Element>();

                    // gather all XML content definitions and their parent nodes
                    Iterator<I_CmsXmlContentValue> it = validValues.iterator();
                    while (it.hasNext()) {
                        // collect all root elements, also for the nested content definitions
                        I_CmsXmlContentValue value = it.next();
                        Element element = value.getElement();
                        validElements.add(element);
                        if (element.supportsParent()) {
                            // get the parent XML node
                            Element root = element.getParent();
                            if ((root != null) && !roots.contains(root)) {
                                // this is a parent node we do not have already in our storage
                                CmsXmlContentDefinition rcd = value.getContentDefinition();
                                if (rcd != null) {
                                    // this value has a valid XML content definition
                                    roots.add(root);
                                    rootCds.add(rcd);
                                } else {
                                    // no valid content definition for the XML value
                                    throw new CmsXmlException(
                                        Messages.get().container(
                                            Messages.ERR_CORRECT_NO_CONTENT_DEF_3,
                                            value.getName(),
                                            value.getTypeName(),
                                            value.getPath()));
                                }
                            }
                        }
                    }

                    for (int le = 0; le < roots.size(); le++) {
                        // iterate all XML content root nodes and correct each XML subtree

                        Element root = roots.get(le);
                        CmsXmlContentDefinition cd = rootCds.get(le);

                        // step 1: first sort the nodes according to the schema, this takes care of re-ordered elements
                        List<List<Element>> nodeLists = new ArrayList<List<Element>>();
                        boolean isMultipleChoice = cd.getSequenceType() == CmsXmlContentDefinition.SequenceType.MULTIPLE_CHOICE;

                        // if it's a multiple choice element, the child elements must not be sorted into their types,
                        // but must keep their original order
                        if (isMultipleChoice) {
                            List<Element> nodeList = new ArrayList<Element>();
                            List<Element> elements = CmsXmlGenericWrapper.elements(root);
                            Set<String> typeNames = cd.getSchemaTypes();
                            for (Element element : elements) {
                                // check if the node type is still in the definition
                                if (typeNames.contains(element.getName())) {
                                    nodeList.add(element);
                                }
                            }
                            checkMaxOccurs(nodeList, cd.getChoiceMaxOccurs(), cd.getTypeName());
                            nodeLists.add(nodeList);
                        }
                        // if it's a sequence, the children are sorted according to the sequence type definition
                        else {
                            for (I_CmsXmlSchemaType type : cd.getTypeSequence()) {
                                List<Element> elements = CmsXmlGenericWrapper.elements(root, type.getName());
                                checkMaxOccurs(elements, type.getMaxOccurs(), type.getTypeName());
                                nodeLists.add(elements);
                            }
                        }

                        // step 2: clear the list of nodes (this will remove all invalid nodes)
                        List<Element> nodeList = CmsXmlGenericWrapper.elements(root);
                        nodeList.clear();
                        Iterator<List<Element>> in = nodeLists.iterator();
                        while (in.hasNext()) {
                            // now add all valid nodes in the right order
                            List<Element> elements = in.next();
                            nodeList.addAll(elements);
                        }

                        // step 3: now append the missing elements according to the XML content definition
                        cd.addDefaultXml(cms, this, root, locale);
                    }
                }
            }
            initDocument();
        }

        // write the modified XML back to the VFS file
        if (m_file != null) {
            // make sure the file object is available
            m_file.setContents(marshal());
        }
        return m_file;
    }
359742
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();

        $locationId = $xml->getElementsByTagName('pickupLocation');
        $static->locationId = StringLiteral::fromXml($locationId);

        $text = $xml->getElementsByTagName('pickupLocationText');
        $static->text = StringLiteral::fromXml($text);

        return $static;
    }
1242257
static public ParsedColInfo fromOrderByXml(AbstractParsedStmt parsedStmt,
            VoltXMLElement orderByXml) {
        // A generic adjuster that just calls finalizeValueTypes
        ExpressionAdjuster adjuster = new ExpressionAdjuster() {
            @Override
            public AbstractExpression adjust(AbstractExpression expr) {
                ExpressionUtil.finalizeValueTypes(expr);
                return expr;
            }
        };

        return fromOrderByXml(parsedStmt, orderByXml, adjuster);
    }
691014
private ChooseConfig searchXmlConfig(ChooseConfig cc, XML xml){
		
		if(isNull(xml.getXmlPath())) return null;
		
    	if((isNull(cc)||cc == ChooseConfig.DESTINATION) && xml.isInheritedMapped(destination))	
    		return ChooseConfig.DESTINATION;
	
		if((isNull(cc)||cc == ChooseConfig.SOURCE) && xml.isInheritedMapped(source))
			return  ChooseConfig.SOURCE;
		
		return null;
    }
848909
public <T> T deserialise(final Class<T> clazz, final String xml)
	{
		final Object obj = deserialise(new InputSource(new StringReader(xml)));

		if (clazz.isInstance(obj))
			return clazz.cast(obj);
		else
			throw new JAXBRuntimeException("XML deserialised to " + obj.getClass() + ", could not cast to the expected " + clazz);
	}
18679
@Override
	public Document readXML() {
		final String xmlString = readString();
		Document doc = null;
		try {
			doc = XMLUtils.stringToDoc(xmlString);
		} catch (IOException ioex) {
			log.error("IOException converting xml to dom", ioex);
		}
		storeReference(doc);
		return doc;
	}
794983
private Element toElement(String xml) {
        DOMResult dom = new DOMResult();
        try {
            TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new StringReader(xml)), dom);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ((Document) dom.getNode()).getDocumentElement();
    }
183504
public String getXML()
    {
        SOAPMessage message = (SOAPMessage)this.getRawData();
        if (message != null)
            return SOAPMessageTransport.messageToString(message);
        return super.getXML();
    }