load a schema using an element's tag. schemas can be a string or a list of strings
502526
def from_tag(cls, tag, schemas, ext='.rnc'):
        """"""
        return cls(fn=cls.filename(tag, schemas, ext=ext))
731346
def load_schema(schema_ref,  # type: Union[CommentedMap, CommentedSeq, Text]
                cache=None   # type: Dict
                ):
    # type: (...) -> Tuple[Loader, Union[Names, SchemaParseException], Dict[Text, Any], Loader]
    

    metaschema_names, _metaschema_doc, metaschema_loader = get_metaschema()
    if cache is not None:
        metaschema_loader.cache.update(cache)
    schema_doc, schema_metadata = metaschema_loader.resolve_ref(schema_ref, "")

    if not isinstance(schema_doc, MutableSequence):
        raise ValueError("Schema reference must resolve to a list.")

    validate_doc(metaschema_names, schema_doc, metaschema_loader, True)
    metactx = schema_metadata.get("@context", {})
    metactx.update(collect_namespaces(schema_metadata))
    schema_ctx = jsonld_context.salad_to_jsonld_context(schema_doc, metactx)[0]

    # Create the loader that will be used to load the target document.
    document_loader = Loader(schema_ctx, cache=cache)

    # Make the Avro validation that will be used to validate the target
    # document
    avsc_names = make_avro_schema(schema_doc, document_loader)

    return document_loader, avsc_names, schema_metadata, metaschema_loader
38349
function(content_schema, raw_tag, widget_config) {

		var tags = Lava.parsers.Common.asBlocks(raw_tag.content);
		tags = this._applyTopDirectives(tags, widget_config);
		if (tags.length) {
			Lava.parsers.Storage.parse(widget_config, tags);
		}

	}
93833
def schema_from_context(context):
    """"""
    item_class = context.get('class')
    return (
        serializer_mapping[item_class] if item_class else BaseSchema,
        context.get('many', False)
    )
125489
function(schema, raw_tag, exclude_name) {

		var tags = Lava.parsers.Common.asBlockType(raw_tag.content, 'tag'),
			i = 0,
			count = tags.length,
			result = {},
			descriptor,
			name;

		for (; i < count; i++) {

			descriptor = schema.properties[tags[i].name];
			if (Lava.schema.DEBUG && !descriptor) Lava.t("Unknown tag in object: " + tags[i].name);
			if (Lava.schema.DEBUG && (tags[i].name in result)) Lava.t('[Storage] duplicate item in object: ' + tags[i].name);
			result[tags[i].name] = this[this._object_property_handlers[descriptor.type]](descriptor, tags[i]);

		}

		for (name in raw_tag.attributes) {

			if (exclude_name && name == 'name') continue;
			descriptor = schema.properties[name];
			if (Lava.schema.DEBUG && (!descriptor || !descriptor.is_attribute)) Lava.t("Unknown attribute in object: " + name);
			if (Lava.schema.DEBUG && (name in result)) Lava.t('[Storage] duplicate item (attribute) in object: ' + name);
			result[name] = this[this._object_attributes_handlers[descriptor.type]](descriptor, raw_tag.attributes[name]);

		}

		return result;

	}
856575
function(schema, raw_tag) {

		if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1 || typeof (raw_tag.content[0]) != 'string')) Lava.t("One string expected in tag content: " + raw_tag.name);
		return Lava.valueToType(schema, raw_tag.content[0]);

	}
1190610
private void parseNesting(Configuration configuration, Document dc) {
        NodeList list = dc.getElementsByTagNameNS(SCHEMA_LOCATION, TAG_NESTING);
        if (list.getLength() > 0) {
            Node el = list.item(0);
            configuration.setNestingLimit(nodeAttribute(el, TAG_NESTING_ATTR_LIMIT, Configuration.DEFAULT_NESTING_LIMIT));
            configuration.setPropagateNestingException(
                    nodeAttribute(el, TAG_NESTING_ATTR_EXCEPTION, Configuration.DEFAULT_PROPAGATE_NESTING_EXCEPTION)
            );
        }
    }
378074
public void load(String path,String tag) throws IOException{
		if(path == null) return;
		dict = MyCollection.loadTSet(path);
		maxLen = 0;
		TObjectHashIterator<String> it = dict.iterator();
		while(it.hasNext()){
			String k = it.next();
			if(k.length()>maxLen){
				maxLen = k.length();
			}
		}		
		name = tag;		
	}
605365
function all(schema, children, node, stack) {
    var nodes = children || []
    var length = nodes.length || 0
    var results = []
    var index = -1
    var result

    stack = stack.concat(node.tagName)

    while (++index < length) {
        result = one(schema, nodes[index], stack)

        if (result) {
            if ('length' in result) {
                results = results.concat(result)
            } else {
                results.push(result)
            }
        }
    }

    return results
}
224498
def schema(self, shex: Optional[Union[str, ShExJ.Schema]]) -> None:
        
        self.pfx = None
        if shex is not None:
            if isinstance(shex, ShExJ.Schema):
                self._schema = shex
            else:
                shext = shex.strip()
                loader = SchemaLoader()
                if ('\n' in shex or '\r' in shex) or shext[0] in '#<_: ':
                    self._schema = loader.loads(shex)
                else:
                    self._schema = loader.load(shex) if isinstance(shex, str) else shex
                if self._schema is None:
                    raise ValueError("Unable to parse shex file")
                self.pfx = PrefixLibrary(loader.schema_text)
951843
def _get_tag(self, name):
        """"""
        if name.endswith("_"):
            if name[:-1] in self._schema.reserved:
                return name[:-1]
        return name
1068628
def LoadFromXml(self, node, handle):
		
		from Ucs import ClassFactory

		self.SetHandle(handle)
		if node.hasAttributes():
			# attributes = node._get_attributes()
			# attCount = attributes._get_length()
			attributes = node.attributes
			attCount = len(attributes)
			for i in range(attCount):
				attNode = attributes.item(i)
				# attr = UcsUtils.WordU(attNode._get_name())
				attr = UcsUtils.WordU(attNode.localName)
				if (attr in UcsUtils.GetUcsPropertyMetaAttributeList(self.classId)):
					atMeta = UcsUtils.GetUcsMethodMeta(self.classId, attr)
					if ((atMeta.io == "Input") or (atMeta.isComplexType)):
						continue
					# self.setattr(attr, str(attNode.nodeValue))
					self.setattr(attr, str(attNode.value))
				# elif (attNode._get_name() in externalMethodAttrs):
				#	self.setattr(attNode._get_name(), str(attNode.nodeValue))
				elif (attNode.localName in externalMethodAttrs):
					self.setattr(attNode.localName, str(attNode.value))

		if (node.hasChildNodes()):
			# childList = node._get_childNodes()
			# childCount = childList._get_length()
			childList = node.childNodes
			childCount = len(childList)
			for i in range(childCount):
				childNode = childList.item(i)
				if (childNode.nodeType != Node.ELEMENT_NODE):
					continue

				cln = UcsUtils.WordU(childNode.localName)
				if cln in UcsUtils.GetUcsPropertyMetaAttributeList(self.classId):
					atMeta = UcsUtils.GetUcsMethodMeta(self.classId, cln)
					if ((atMeta.io == "Output") and (atMeta.isComplexType)):
						c = ClassFactory(atMeta.fieldType)
						if (c != None):
							self.setattr(cln, c)
							c.LoadFromXml(childNode, handle)
912304
def parse_smarttag(document, container, tag_elem):
    ""

    tag = doc.SmartTag()

    tag.element = tag_elem.attrib[_name('{{{w}}}element')]

    for elem in tag_elem:
        if elem.tag == _name('{{{w}}}r'):
            parse_text(document, tag, elem)

        if elem.tag == _name('{{{w}}}smartTag'):
            parse_smarttag(document, tag, elem)

    container.elements.append(tag)

    return
382229
def schematron(self, tag=None, schemas=None, schemafn=None, ext='.sch'):
        
        from . import PATH
        from .xslt import XSLT

        schematron_path = os.path.join(PATH, 'schematron', 'trunk', 'schematron', 'code')

        # select the schema filename
        tag = tag or self.root.tag
        schemas = schemas or self.schemas
        schemafn = (
            schemafn
            or Schema.filename(tag, schemas, ext=ext)
            or Schema.filename(tag, schemas, ext='.rng')
            or Schema.filename(tag, schemas, ext='.rnc')
        )

        assert schemafn is not None and os.path.exists(schemafn)

        # ensure that an up-to-date Schematron schema file is available.
        schfn = File(fn=schemafn).clean_filename(ext='.sch')
        fbase, fext = os.path.splitext(schfn)
        if not (os.path.exists(schfn)) or (
            os.path.exists(fbase + '.rnc')
            and File(fn=schfn).last_modified < File(fn=fbase + '.rnc').last_modified
        ):
            # create the Schematron file from the .rnc
            schfn = Schema(fn=fbase + '.rnc').schematron()
        elif not (os.path.exists(schfn)) or (
            os.path.exists(fbase + '.rng')
            and File(fn=schfn).last_modified < File(fn=fbase + '.rng').last_modified
        ):
            # create the Schematron file from the .rng
            schfn = Schema(fn=fbase + '.rng').schematron()

        assert schfn is not None and os.path.exists(schfn)

        # ensure that an up-to-date Schematron XSLT file is available
        sch_xslt_fn = schfn + '.xslt'
        if (
            not os.path.exists(sch_xslt_fn)
            or File(fn=sch_xslt_fn).last_modified < File(fn=schfn).last_modified
        ):
            # The Schematron XSLT doesn't exist or is out-of-date, so we need to update it
            sch = XML(fn=schfn)
            sch.fn = sch_xslt_fn

            # We're using the XSLT 1.0 version of Schematron.
            # even though we use XSLT 2.0+ XPath functions -- the converter doesn't actually read the patterns.
            # (tried the XSLT 2.0 version with Saxon9HE, but Schematron assumes XSLT 1.0 compatibility,
            # which Saxon9HE doesn't support.)
            for xslfb in [
                'iso_dsdl_include.xsl',
                'iso_abstract_expand.xsl',
                'iso_svrl_for_xslt1.xsl',
            ]:
                xslt = XSLT(fn=os.path.join(schematron_path, xslfb))
                sch.root = xslt.saxon6(sch.root).getroot()
                sch.write()

            # change the XSLT version from "1.0" to "2.0". (Later we might support 3.0)
            sch.root.set('version', '2.0')
            sch.write()

        assert sch_xslt_fn is not None and os.path.exists(sch_xslt_fn)

        # validate the XML against the Schematron XSLT using Saxon 9 (XSLT 3.0 / XPath 3.1)
        sch_xslt = XSLT(fn=sch_xslt_fn)
        report = XML(root=sch_xslt.saxon9(self.root).getroot())

        # return the errors in the report_xml as a list of errors, with line numbers
        errors = []
        for failure in report.xpath(
            report.root,
            "//svrl:failed-assert",
            namespaces={'svrl': "http://purl.oclc.org/dsdl/svrl"},
        ):
            for e in self.xpath(self.root, failure.get('location')):
                errors.append(
                    "%s:%d <%s %s>: error: %s"
                    % (
                        self.fn,
                        e.sourceline or -1,
                        self.tag_name(e),
                        " ".join(['%s="%s"' % (k, v) for k, v in e.attrib.items()]),
                        etree.tounicode(failure, method='text').strip(),
                    )
                )
        return errors
413082
def loadSchema(uri, base_uri=None):
    

    # uri to use for reporting errors - include base uri if any
    if uri in _loaded_schemas:
        return _loaded_schemas[uri]

    error_uri = uri
    if base_uri is not None:
        error_uri += ' (base URI %s)' % base_uri


    try:
        logger.debug('Loading schema %s' % uri)
        _loaded_schemas[uri] = etree.XMLSchema(etree.parse(uri,
                                                           parser=_get_xmlparser(),
                                                           base_url=base_uri))
        return _loaded_schemas[uri]
    except IOError as io_err:
        # add a little more detail to the error message - but should still be an IO error
        raise IOError('Failed to load schema %s : %s' % (error_uri, io_err))
    except etree.XMLSchemaParseError as parse_err:
        # re-raise as a schema parse error, but ensure includes details about schema being loaded
        raise etree.XMLSchemaParseError('Failed to parse schema %s -- %s' % (error_uri, parse_err))
262313
function tag(node, tagName){
    var element = get(node) || document;

    if (tagName == '*' && element.all)
      return arrayFrom(element.all);
    else
      return arrayFrom(element.getElementsByTagName(tagName || '*'));
  }
251266
def loadFromStream(self, file, url=None):
        
        reader = self.__readerClass()
        reader.loadDocument(file)
        schema = XMLSchema()
        if url is not None:
             schema.setBaseUrl(url)
        schema.load(reader)
        self.__setIncludes(schema)
        self.__setImports(schema)
        return schema