public void addRef(Ref _ref) { int? priority = _ref.getPriority(); refs.Add(_ref); prioritizedRefs.addObject((priority == null) ? "null" : priority.ToString(), _ref); }
//throws UriFormatException, ParseException /** * This method populates the obj from DOM. It does not keep a * copy of the DOM around. Whitespace information is lost in this process. */ public void fromDOM(XmlElement oElem) { reset(); // get the id attribute if (oElem.hasAttributeNS(Tags.NS_XML, Tags.ATTR_ID_LOW)) xmlID = oElem.getAttributeNS(Tags.NS_XML, Tags.ATTR_ID_LOW); if (oElem.hasAttributeNS(Tags.NS_XML, Tags.ATTR_IDREF)) idRef = oElem.getAttributeNS(Tags.NS_XML, Tags.ATTR_IDREF); if (oElem.hasAttributeNS(null, Tags.ATTR_XRD_VERSION)) version = oElem.getAttributeNS(null, Tags.ATTR_XRD_VERSION); for (XmlElement oChild = (XmlElement)oElem.FirstChild; oChild != null; oChild = (XmlElement)oChild.NextSibling) { string sChildName = oChild.LocalName ?? oChild.Name; if (sChildName.Equals(Tags.TAG_TYPE)) { XRDType t = new XRDType(); t.fromXML(oChild); types.Add(t); } else if (sChildName.Equals(Tags.TAG_QUERY)) { Query q = new Query(); q.fromXML(oChild); this.query = q; } else if (sChildName.Equals(Tags.TAG_STATUS)) { Status s = new Status(); s.fromXML(oChild); this.status = s; } else if (sChildName.Equals(Tags.TAG_SERVERSTATUS)) { ServerStatus s = new ServerStatus(); s.fromXML(oChild); this.serverStatus = s; } else if (sChildName.Equals(Tags.TAG_EXPIRES)) { // only accept the first Expires element and make sure it expires = new Expires(XmlConvert.ToDateTime(oChild.FirstChild.Value)); } else if (sChildName.Equals(Tags.TAG_PROVIDERID)) { ProviderID p = new ProviderID(); p.fromXML(oChild); this.providerID = p; } else if (sChildName.Equals(Tags.TAG_LOCALID)) { addLocalID(new LocalID(oChild)); } else if (sChildName.Equals(Tags.TAG_EQUIVID)) { equivIDs.Add(new EquivID(oChild)); } else if (sChildName.Equals(Tags.TAG_CANONICALID)) { canonicalIDs.Add(new CanonicalID(oChild)); } else if (sChildName.Equals(Tags.TAG_CANONICALEQUIVID)) { canonicalEquivID = new CanonicalEquivID(); canonicalEquivID.fromXML(oChild); } else if (sChildName.Equals(Tags.TAG_REDIRECT)) { Redirect _ref = new Redirect(oChild); addRedirect(_ref); } else if (sChildName.Equals(Tags.TAG_REF)) { Ref _ref = new Ref(oChild); addRef(_ref); } else if (sChildName.Equals(Tags.TAG_SERVICE)) { addService(new Service(oChild)); } else if ( (oChild.NamespaceURI != null) && oChild.NamespaceURI.Equals(Tags.NS_SAML) && (oChild.LocalName != null) && oChild.LocalName.Equals(Tags.TAG_ASSERTION)) { samlAssertion = new Assertion(oChild); } // Added this code to support extensions in Authority XmlElement else { ArrayList oVector = (ArrayList)moOtherChildrenVectorsMap[sChildName]; if (oVector == null) { oVector = new ArrayList(); moOtherChildrenVectorsMap[sChildName] = oVector; } oVector.Add(oChild.CloneNode(true)); } } }
public virtual bool ReadToDescendant(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, nameof(localName)); } if (namespaceURI == null) { throw new ArgumentNullException(nameof(namespaceURI)); } int depth = this.Depth; if (this.NodeType != XmlNodeType.Element) { if (this.ReadState != ReadState.Initial) { return(false); } --depth; } else if (this.IsEmptyElement) { return(false); } localName = this.NameTable.Add(localName); namespaceURI = this.NameTable.Add(namespaceURI); while (this.Read() && this.Depth > depth) { if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI)) { return(true); } } return(false); }
public virtual bool ReadToNextSibling(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, nameof(localName)); } if (namespaceURI == null) { throw new ArgumentNullException(nameof(namespaceURI)); } localName = this.NameTable.Add(localName); namespaceURI = this.NameTable.Add(namespaceURI); XmlNodeType nodeType; do { this.SkipSubtree(); nodeType = this.NodeType; if (nodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI)) { return(true); } }while (nodeType != XmlNodeType.EndElement && !this.EOF); return(false); }
// SxS: This function calls ValidateElement on XmlSchemaValidator which is annotated with ResourceExposure attribute. // Since the resource names passed to ValidateElement method are null and the function does not expose any resources // it is fine to suppress the SxS warning. private void ValidateElement() { _nsManager.PushScope(); XmlElement elementNode = _currentNode as XmlElement; Debug.Assert(elementNode != null); XmlAttributeCollection attributes = elementNode.Attributes; XmlAttribute attr = null; //Find Xsi attributes that need to be processed before validating the element string xsiNil = null; string xsiType = null; for (int i = 0; i < attributes.Count; i++) { attr = attributes[i]; string objectNs = attr.NamespaceURI; string objectName = attr.LocalName; Debug.Assert(_nameTable.Get(attr.NamespaceURI) != null); Debug.Assert(_nameTable.Get(attr.LocalName) != null); if (Ref.Equal(objectNs, _nsXsi)) { if (Ref.Equal(objectName, _xsiType)) { xsiType = attr.Value; } else if (Ref.Equal(objectName, _xsiNil)) { xsiNil = attr.Value; } } else if (Ref.Equal(objectNs, _nsXmlNs)) { _nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value); } } _validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo, xsiType, xsiNil, null, null); ValidateAttributes(elementNode); _validator.ValidateEndOfAttributes(_schemaInfo); //If element has children, drill down for (XmlNode child = elementNode.FirstChild; child != null; child = child.NextSibling) { ValidateNode(child); } //Validate end of element _currentNode = elementNode; //Reset current Node for validation call back _validator.ValidateEndElement(_schemaInfo); //Get XmlName, as memberType / validity might be set now if (_psviAugmentation) { elementNode.XmlName = _document.AddXmlName(elementNode.Prefix, elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo); if (_schemaInfo.IsDefault) { //the element has a default value XmlText textNode = _document.CreateTextNode(_schemaInfo.SchemaElement.ElementDecl.DefaultValueRaw); elementNode.AppendChild(textNode); } } _nsManager.PopScope(); //Pop current namespace scope }
public virtual bool ReadToFollowing(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, nameof(localName)); } if (namespaceURI == null) { throw new ArgumentNullException(nameof(namespaceURI)); } localName = this.NameTable.Add(localName); namespaceURI = this.NameTable.Add(namespaceURI); while (this.Read()) { if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI)) { return(true); } } return(false); }
/// Add reference to .NET assembly specified either by filename or by name public Assembly AddReference(string from, string name, bool embed, bool forceLoad, string loadIfStartsWith) { bool add = true; foreach (var r in _references) { if (!string.IsNullOrEmpty(from) && r.From == from) { if (!forceLoad) return null; add = false; } if (!string.IsNullOrEmpty(name) && r.Name == name) { if (!forceLoad) return null; add = false; } } var rNew = new Ref { From = from, Name = name, Embed = embed }; if (add) _references.Add(rNew); foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { if (!string.IsNullOrEmpty(name) && a.FullName == name) return a; } if (forceLoad) return rNew.ForceLoad(_verboseWriter); if (loadIfStartsWith!=null) _notLoadedReferences.Add(rNew, loadIfStartsWith); return null; }
public virtual void AddNamespace(string prefix, string uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } prefix = _nameTable.Add(prefix); uri = _nameTable.Add(uri); if ((Ref.Equal(_xml, prefix) && !uri.Equals(XmlReservedNs.NsXml))) { throw new ArgumentException(SR.Xml_XmlPrefix); } if (Ref.Equal(_xmlNs, prefix)) { throw new ArgumentException(SR.Xml_XmlnsPrefix); } int declIndex = LookupNamespaceDecl(prefix); int previousDeclIndex = -1; if (declIndex != -1) { if (_nsdecls[declIndex].scopeId == _scopeId) { // redefine if in the same scope _nsdecls[declIndex].uri = uri; return; } else { // otherwise link previousDeclIndex = declIndex; } } // set new namespace declaration if (_lastDecl == _nsdecls.Length - 1) { NamespaceDeclaration[] newNsdecls = new NamespaceDeclaration[_nsdecls.Length * 2]; Array.Copy(_nsdecls, 0, newNsdecls, 0, _nsdecls.Length); _nsdecls = newNsdecls; } _nsdecls[++_lastDecl].Set(prefix, uri, _scopeId, previousDeclIndex); // add to hashTable if (_useHashtable) { _hashTable[prefix] = _lastDecl; } // or create a new hashTable if the threashold has been reached else if (_lastDecl >= MinDeclsCountForHashtable) { // add all to hash table Debug.Assert(_hashTable == null); _hashTable = new Dictionary <string, int>(_lastDecl); for (int i = 0; i <= _lastDecl; i++) { _hashTable[_nsdecls[i].prefix] = i; } _useHashtable = true; } }
// SxS: This function calls ValidateElement on XmlSchemaValidator which is annotated with ResourceExposure attribute. // Since the resource names (namespace location) are not provided directly by the user (they are read from the source // document) and the function does not expose any resources it is fine to suppress the SxS warning. private async Task ProcessElementEventAsync() { if (_processInlineSchema && IsXSDRoot(_coreReader.LocalName, _coreReader.NamespaceURI) && _coreReader.Depth > 0) { _xmlSchemaInfo.Clear(); _attributeCount = _coreReaderAttributeCount = _coreReader.AttributeCount; if (!_coreReader.IsEmptyElement) { //If its not empty schema, then parse else ignore _inlineSchemaParser = new Parser(SchemaType.XSD, _coreReaderNameTable, _validator.SchemaSet.GetSchemaNames(_coreReaderNameTable), _validationEvent); await _inlineSchemaParser.StartParsingAsync(_coreReader, null).ConfigureAwait(false); _inlineSchemaParser.ParseReaderNode(); _validationState = ValidatingReaderState.ParseInlineSchema; } else { _validationState = ValidatingReaderState.ClearAttributes; } } else { //Validate element //Clear previous data _atomicValue = null; _originalAtomicValueString = null; _xmlSchemaInfo.Clear(); if (_manageNamespaces) { _nsManager.PushScope(); } //Find Xsi attributes that need to be processed before validating the element string xsiSchemaLocation = null; string xsiNoNamespaceSL = null; string xsiNil = null; string xsiType = null; if (_coreReader.MoveToFirstAttribute()) { do { string objectNs = _coreReader.NamespaceURI; string objectName = _coreReader.LocalName; if (Ref.Equal(objectNs, _nsXsi)) { if (Ref.Equal(objectName, _xsiSchemaLocation)) { xsiSchemaLocation = _coreReader.Value; } else if (Ref.Equal(objectName, _xsiNoNamespaceSchemaLocation)) { xsiNoNamespaceSL = _coreReader.Value; } else if (Ref.Equal(objectName, _xsiType)) { xsiType = _coreReader.Value; } else if (Ref.Equal(objectName, _xsiNil)) { xsiNil = _coreReader.Value; } } if (_manageNamespaces && Ref.Equal(_coreReader.NamespaceURI, _nsXmlNs)) { _nsManager.AddNamespace(_coreReader.Prefix.Length == 0 ? string.Empty : _coreReader.LocalName, _coreReader.Value); } } while (_coreReader.MoveToNextAttribute()); _coreReader.MoveToElement(); } _validator.ValidateElement(_coreReader.LocalName, _coreReader.NamespaceURI, _xmlSchemaInfo, xsiType, xsiNil, xsiSchemaLocation, xsiNoNamespaceSL); ValidateAttributes(); _validator.ValidateEndOfAttributes(_xmlSchemaInfo); if (_coreReader.IsEmptyElement) { await ProcessEndElementEventAsync().ConfigureAwait(false); } _validationState = ValidatingReaderState.ClearAttributes; } }
// Reads to the first descendant of the current element with the given LocalName and NamespaceURI. public virtual bool ReadToDescendant(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName"); } if (namespaceURI == null) { throw new ArgumentNullException("namespaceURI"); } // save the element or root depth int parentDepth = Depth; if (NodeType != XmlNodeType.Element) { // adjust the depth if we are on root node if (ReadState == ReadState.Initial) { Debug.Assert(parentDepth == 0); parentDepth--; } else { return(false); } } else if (IsEmptyElement) { return(false); } // atomize local name and namespace localName = NameTable.Add(localName); namespaceURI = NameTable.Add(namespaceURI); // find the descendant while (Read() && Depth > parentDepth) { if (NodeType == XmlNodeType.Element && Ref.Equal(localName, LocalName) && Ref.Equal(namespaceURI, NamespaceURI)) { return(true); } } Debug.Assert(NodeType == XmlNodeType.EndElement || (parentDepth == -1 && ReadState == ReadState.EndOfFile)); return(false); }
// Reads to the following element with the given LocalName and NamespaceURI. public virtual bool ReadToFollowing(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, "localName"); } if (namespaceURI == null) { throw new ArgumentNullException("namespaceURI"); } // atomize local name and namespace localName = NameTable.Add(localName); namespaceURI = NameTable.Add(namespaceURI); // find following element with that name while (Read()) { if (NodeType == XmlNodeType.Element && Ref.Equal(localName, LocalName) && Ref.Equal(namespaceURI, NamespaceURI)) { return(true); } } return(false); }
internal string GetPrefixOfNamespaceStrict(string namespaceURI) { XmlDocument doc = Document; if (doc != null) { namespaceURI = doc.NameTable.Add(namespaceURI); XmlNode node = this; while (node != null) { if (node.NodeType == XmlNodeType.Element) { XmlElement elem = (XmlElement)node; if (elem.HasAttributes) { XmlAttributeCollection attrs = elem.Attributes; for (int iAttr = 0; iAttr < attrs.Count; iAttr++) { XmlAttribute attr = attrs[iAttr]; if (attr.Prefix.Length == 0) { if (Ref.Equal(attr.LocalName, doc.strXmlns)) { if (attr.Value == namespaceURI) { return(string.Empty); // found xmlns="namespaceURI" } } } else if (Ref.Equal(attr.Prefix, doc.strXmlns)) { if (attr.Value == namespaceURI) { return(attr.LocalName); // found xmlns:prefix="namespaceURI" } } else if (Ref.Equal(attr.NamespaceURI, namespaceURI)) { return(attr.Prefix); // found prefix:attr // with prefix bound to namespaceURI } } } if (Ref.Equal(node.NamespaceURI, namespaceURI)) { return(node.Prefix); } node = node.ParentNode; } else if (node.NodeType == XmlNodeType.Attribute) { node = ((XmlAttribute)node).OwnerElement; } else { node = node.ParentNode; } } if (Ref.Equal(doc.strReservedXml, namespaceURI)) { // xmlns:xml return(doc.strXml); } else if (Ref.Equal(doc.strReservedXmlns, namespaceURI)) { // xmlns:xmlns return(doc.strXmlns); } } return(null); }
internal string GetNamespaceOfPrefixStrict(string prefix) { XmlDocument doc = Document; if (doc != null) { prefix = doc.NameTable.Get(prefix); if (prefix == null) { return(null); } XmlNode node = this; while (node != null) { if (node.NodeType == XmlNodeType.Element) { XmlElement elem = (XmlElement)node; if (elem.HasAttributes) { XmlAttributeCollection attrs = elem.Attributes; if (prefix.Length == 0) { for (int iAttr = 0; iAttr < attrs.Count; iAttr++) { XmlAttribute attr = attrs[iAttr]; if (attr.Prefix.Length == 0) { if (Ref.Equal(attr.LocalName, doc.strXmlns)) { return(attr.Value); // found xmlns } } } } else { for (int iAttr = 0; iAttr < attrs.Count; iAttr++) { XmlAttribute attr = attrs[iAttr]; if (Ref.Equal(attr.Prefix, doc.strXmlns)) { if (Ref.Equal(attr.LocalName, prefix)) { return(attr.Value); // found xmlns:prefix } } else if (Ref.Equal(attr.Prefix, prefix)) { return(attr.NamespaceURI); // found prefix:attr } } } } if (Ref.Equal(node.Prefix, prefix)) { return(node.NamespaceURI); } node = node.ParentNode; } else if (node.NodeType == XmlNodeType.Attribute) { node = ((XmlAttribute)node).OwnerElement; } else { node = node.ParentNode; } } if (Ref.Equal(doc.strXml, prefix)) { // xmlns:xml return(doc.strReservedXml); } else if (Ref.Equal(doc.strXmlns, prefix)) { // xmlns:xmlns return(doc.strReservedXmlns); } } return(null); }