Create a new MDWrap by parsing root.

        :param root: Element or ElementTree to be parsed into a MDWrap.
        :raises exceptions.ParseError: If mdWrap does not contain MDTYPE
        :raises exceptions.ParseError: If xmlData contains no children
491063
def parse(cls, root):
        
        if root.tag != utils.lxmlns("mets") + "mdWrap":
            raise exceptions.ParseError(
                "MDWrap can only parse mdWrap elements with METS namespace."
            )
        mdtype = root.get("MDTYPE")
        if not mdtype:
            raise exceptions.ParseError("mdWrap must have a MDTYPE")
        othermdtype = root.get("OTHERMDTYPE")
        document = root.xpath("mets:xmlData/*", namespaces=utils.NAMESPACES)
        if len(document) == 0:
            raise exceptions.ParseError(
                "All mdWrap/xmlData elements must have at least one child; this"
                " one has none"
            )
        elif len(document) == 1:
            document = document[0]

        # Create a copy, so that the element is not moved by duplicate references.
        document = copy.deepcopy(document)

        return cls(document, mdtype, othermdtype)
963918
public static boolean start(RootDoc root) {
		try {
			HtmlDoclet doclet = new HtmlDoclet();
			return doclet.start(doclet, root);
		} finally {
			ConfigurationImpl.reset();
		}
	}
462094
def setRootElement(self, root):
        
        if root is None: root__o = None
        else: root__o = root._o
        ret = libxml2mod.xmlDocSetRootElement(self._o, root__o)
        if ret is None:return None
        __tmp = xmlNode(_obj=ret)
        return __tmp
974482
public static FeaturableConfig imports(Xml root)
    {
        Check.notNull(root);

        final String clazz;
        if (root.hasChild(ATT_CLASS))
        {
            clazz = root.getChild(ATT_CLASS).getText();
        }
        else
        {
            clazz = DEFAULT_CLASS_NAME;
        }

        final String setup;
        if (root.hasChild(ATT_SETUP))
        {
            setup = root.getChild(ATT_SETUP).getText();
        }
        else
        {
            setup = Constant.EMPTY_STRING;
        }

        return new FeaturableConfig(clazz, setup);
    }
582139
def parse_root(raw):
    ""
    if sys.version < '3':
        fp = StringIO(raw)
    else:
        fp = BytesIO(raw.encode('UTF-8'))
    for event, element in etree.iterparse(fp, events=('start',)):
        return (element.tag, element.attrib)
656214
def parse(self, lines, root):
    

    lst = IgnoreList(root)
    lst.parse(lines)
    self.append(lst)
171271
def build_tree(self):
        
        if self.built:
            return
        self.doc_root = self.root.element()
        for key in self.sorted_fields():
            if key not in self._fields:
                continue
            field = self._fields[key]
            if field != self.root:
                if isinstance(field, XmlModel):
                    field.build_tree()
                    if (self.drop_empty and field.drop_empty
                        and len(field.doc_root) == 0):
                        continue
                    self.doc_root.append(field.doc_root)
                elif isinstance(field, list):
                    # we just allow XmlFields and XmlModels
                    # Also xml as str for memory management
                    for item in field:
                        if isinstance(item, XmlField):
                            ele = item.element()
                            if self.drop_empty and len(ele) == 0:
                                continue
                            self.doc_root.append(ele)
                        elif isinstance(item, XmlModel):
                            item.build_tree()
                            if self.drop_empty and len(item.doc_root) == 0:
                                continue
                            self.doc_root.append(item.doc_root)
                        elif isinstance(item, (six.text_type, six.string_types)):
                            ele = etree.fromstring(clean_xml(item))
                            self.doc_root.append(ele)
                        item = None
                elif (field.parent or self.root.name) == self.root.name:
                    ele = field.element()
                    if self.drop_empty and len(ele) == 0 and not ele.text:
                        continue
                    ele = field.element(parent=self.doc_root)
                else:
                    nodes = [n for n in self.doc_root.iterdescendants(
                                            tag=field.parent)]
                    if nodes:
                        ele = field.element()
                        if (self.drop_empty and len(ele) == 0 and not ele.text):
                            continue
                        ele = field.element(parent=nodes[0])
                    #else:
                    #    raise RuntimeError("No parent found!")
        self.built = True
233255
public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) {
		try {
			CollectionWrapper wrapper = new CollectionWrapper();
			wrapper.collection = root;

			JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName),
					CollectionWrapper.class, wrapper);

			StringWriter writer = new StringWriter();
			createMarshaller(clazz, encoding).marshal(wrapperElement, writer);

			return writer.toString();
		} catch (JAXBException e) {
			throw ExceptionUtil.unchecked(e);
		}
	}
1185289
public static FileSystemLayout create(String root) {

        // THORN-2178: Check if a System property has been set to a specific implementation class.
        String implClassName = System.getProperty(CUSTOM_LAYOUT_CLASS);
        if (implClassName != null) {
            implClassName = implClassName.trim();
            if (!implClassName.isEmpty()) {
                FileSystemLayout layout = null;
                // Attempt to load the specified class implementation.
                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                try {
                    Class<?> clazz = loader.loadClass(implClassName);
                    // Check if clazz is an implementation of FileSystemLayout or not.
                    if (FileSystemLayout.class.isAssignableFrom(clazz)) {
                        Class<? extends FileSystemLayout> implClazz = clazz.asSubclass(FileSystemLayout.class);
                        // Check if we have an appropriate constructor or not.
                        Constructor<? extends FileSystemLayout> ctor = implClazz.getDeclaredConstructor(String.class);
                        layout = ctor.newInstance(root);
                    } else {
                        String msg = String.format("%s does not subclass %s", implClassName, FileSystemLayout.class.getName());
                        LOG.warn(SwarmMessages.MESSAGES.invalidFileSystemLayoutProvided(msg));
                    }
                } catch (ReflectiveOperationException e) {
                    Throwable cause = e.getCause();
                    String msg = String.format("Unable to instantiate layout class (%s) due to: %s", implClassName,
                                               cause != null ? cause.getMessage() : e.getMessage());
                    LOG.warn(SwarmMessages.MESSAGES.invalidFileSystemLayoutProvided(msg));
                    LOG.debug(SwarmMessages.MESSAGES.invalidFileSystemLayoutProvided(msg), e);
                    throw SwarmMessages.MESSAGES.cannotIdentifyFileSystemLayout(msg);
                }

                if (layout != null) {
                    return layout;
                }
            } else {
                LOG.warn(SwarmMessages.MESSAGES.invalidFileSystemLayoutProvided("Implementation class name is empty."));
            }
        }

        String mavenBuildFile = resolveMavenBuildFileName();

        if (Files.exists(Paths.get(root, mavenBuildFile))) {
            return new MavenFileSystemLayout(root);
        } else if (Files.exists(Paths.get(root, BUILD_GRADLE))) {
            return new GradleFileSystemLayout(root);
        }

        throw SwarmMessages.MESSAGES.cannotIdentifyFileSystemLayout(root);
    }
1243948
def to_xml(self, root):
        '''
        
        '''
        if not len(self.__custom_elements):
            return

        for uri, tags in self.__custom_elements.items():
            prefix, url = uri.split(":", 1)
            for name, value in tags.items():
                self.__createElementNS(root, url, prefix + ":" + name, value)

        return root
800540
def create_from_xmlfile(cls, xmlfile, extdir=None):
        
        root = ElementTree.ElementTree(file=xmlfile).getroot()
        srcs = root.findall('source')
        if len(srcs) == 0:
            raise Exception('No sources found.')
        return cls.create_from_xml(srcs[0], extdir=extdir)
927583
def fromstring(cls, root_name, data):
        
        try:
            return cls(root_name, cElementTree.fromstring(data))
        except _ETREE_EXCEPTIONS as error:
            raise InvalidXMLError(
                '"{}" XML is not parsable. Message: {}'.format(
                    root_name, error.message
                )
            )
1137308
def newCDataBlock(self, content, len):
        
        ret = libxml2mod.xmlNewCDataBlock(self._o, content, len)
        if ret is None:raise treeError('xmlNewCDataBlock() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp
411567
def data(self, root):
        ''''''

        value = self.dict()

        # Add attributes specific 'attributes' key
        if root.attrib:
            value['attributes'] = self.dict()
            for attr, attrval in root.attrib.items():
                value['attributes'][unicode(attr)] = self._fromstring(attrval)

        # Add children to specific 'children' key
        children_list = self.list()
        children = [node for node in root if isinstance(node.tag, basestring)]

        # Add root text
        if root.text and self.text_content is not None:
            text = root.text.strip()
            if text:
                if self.simple_text and len(children) == len(root.attrib) == 0:
                    value = self._fromstring(text)
                else:
                    children_list = [self._fromstring(text), ]

        for child in children:
            child_data = self.data(child)
            children_list.append(child_data)

        # Flatten children
        if len(root.attrib) == 0 and len(children_list) == 1:
            value = children_list[0]

        elif len(children_list) > 0:
            value['children'] = children_list

        return self.dict([(unicode(root.tag), value)])
767394
public static FramesConfig imports(Xml root)
    {
        Check.notNull(root);

        final Xml node = root.getChild(NODE_FRAMES);
        final int horizontals = node.readInteger(ATT_HORIZONTAL);
        final int verticals = node.readInteger(ATT_VERTICAL);
        final int offsetX = node.readInteger(0, ATT_OFFSET_X);
        final int offsetY = node.readInteger(0, ATT_OFFSET_Y);

        return new FramesConfig(horizontals, verticals, offsetX, offsetY);
    }
71502
public JimfsPath createRoot(Name root) {
    return createPath(checkNotNull(root), ImmutableList.<Name>of());
  }
724165
protected void init(com.sun.javadoc.RootDoc root,
                      String dest,
                      String templateClassName) throws Exception {

        mRootDoc = new RootDoc(root);

        mDest = new File(dest);
        mDest.mkdirs();

        mTemplateClassName = templateClassName;
        if (mTemplateClassName == null) {
            printWarning("No template name");
            return;
        }

        String[] templatePath = ClassDoc.parseClassName(mTemplateClassName);

        //
        // Load the specified template class
        //

        TemplateLoader loader =
            new TemplateLoader(getClass().getClassLoader(),
                               templatePath[0]);

        mTemplate = loader.getTemplate(templatePath[1]);

        Class[] params = mTemplate.getParameterTypes();
        if (params.length != 1 || params[0] != ClassDoc.class) {
            printError("Template has incorrect param signature");
        }
    }