/** * Parses XML from a list of strings. * * @param xml String iterable containing valid XML. * @return XML document. * @throws Exception Unspecified exception. */ public static Document parseXMLFromList(Iterable<String> xml) throws Exception { return parseXMLFromString(StrUtil.fromList(xml)); }
/** * Parse the layout from XML content. * * @param xml The XML content to parse. * @return The root layout element. */ public static Layout parseText(String xml) { try { return parseDocument(XMLUtil.parseXMLFromString(xml)); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
.trimToNull(XMLUtil.parseXMLFromString(sb.toString()).getDocumentElement().getTextContent());
/** * Returns the layout as an xml-formatted string. */ @Override public String toString() { if (root == null) { return ""; } try { Document doc = XMLUtil.parseXMLFromString("<layout/>"); Element node = doc.getDocumentElement(); buildDocument(node, root); LayoutUtil.copyAttributes(root.getAttributes(), node); node.setAttribute("version", LAYOUT_VERSION); node.setAttribute("name", layoutName); return XMLUtil.toString(doc); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
/** * Parses an xml extension from an xml string. * * @param xml XML containing the extension. * @param tagName The top level tag name. * @return Result of the parsed extension. * @throws Exception Unspecified exception. */ protected Object fromXml(String xml, String tagName) throws Exception { Document document = XMLUtil.parseXMLFromString(xml); NodeList nodeList = document.getElementsByTagName(tagName); if (nodeList == null || nodeList.getLength() != 1) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Top level tag '" + tagName + "' was not found."); } Element element = (Element) nodeList.item(0); Class<?> beanClass = getBeanClass(element); BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(beanClass); doParse(element, builder); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.setParentBeanFactory(SpringUtil.getAppContext()); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); factory.registerBeanDefinition(tagName, beanDefinition); return factory.getBean(tagName); }