Exemplo n.º 1
0
        private bool isVariableCaptured(QName name)
        {
            VariableScope scope = _innerScope;

            while (scope != null)
            {
                if (name.Equals(scope.name))
                {
                    return(true);
                }
                scope = scope.nextScope;
            }
            return(false);
        }
Exemplo n.º 2
0
        private org.eclipse.wst.xml.xpath2.api.typesystem.ItemType getVariableType(QName name)
        {
            VariableScope scope = _innerScope;

            while (scope != null)
            {
                if (name.Equals(scope.name))
                {
                    return(scope.typeDef);
                }
                scope = scope.nextScope;
            }
            return(_sc.InScopeVariables.getVariableType(name.asQName()));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Method which sets the Uri for this Element Event.
 /// </summary>
 /// <param name="u">Uri Reference to set Uri from.</param>
 /// <remarks>This can only be used on Elements which are rdf:li and thus need expanding into actual list elements according to List Expansion rules.  Attempting to set the Uri on any other Element Event will cause an Error message.</remarks>
 public void SetUri(UriReferenceEvent u)
 {
     if (QName.Equals("rdf:li"))
     {
         // Split the QName into Namespace and Local Name
         String   qname = u.Identifier;
         String[] parts = qname.Split(':');
         _namespace = parts[0];
         _localname = parts[1];
     }
     else
     {
         throw new RdfParseException("It is forbidden to change the URI of an Element Event unless it is a rdf:li Element and thus needs expanding to the form rdf:_X according to List Expansion rules");
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Load the DOM tree from the Open XML part.
        /// </summary>
        /// <param name="openXmlPart">The part this root element to be loaded from.</param>
        /// <param name="partStream">The stream of the part.</param>
        /// <returns>
        /// Returns true when the part stream is loaded successfully into this root element.
        /// Returns false when the part stream does not contain any xml element.
        /// </returns>
        /// <exception cref="InvalidDataException">Thrown when the part stream contains an incorrect root element.</exception>
        internal bool LoadFromPart(OpenXmlPart openXmlPart, Stream partStream)
        {
            if (partStream.Length < 4)
            {
                // The XmlReader.Read() method requires at least four bytes from the data stream in order to begin parsing.
                return(false);
            }

            var context = RootElementContext;

            // set MaxCharactersInDocument to limit the part size on loading DOM.
            context.XmlReaderSettings.MaxCharactersInDocument = openXmlPart.MaxCharactersInPart;

#if FEATURE_XML_PROHIBIT_DTD
            context.XmlReaderSettings.ProhibitDtd = true;                     // set true explicitly for security fix
#else
            context.XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit; // set to prohibit explicitly for security fix
#endif

            using (var xmlReader = XmlConvertingReaderFactory.Create(partStream, context.XmlReaderSettings, openXmlPart.OpenXmlPackage.StrictRelationshipFound))
            {
                context.MCSettings = openXmlPart.MCSettings;

                xmlReader.Read();

                if (xmlReader.NodeType == XmlNodeType.XmlDeclaration)
                {
                    var standaloneAttribute = xmlReader.GetAttribute("standalone");
                    if (standaloneAttribute is not null)
                    {
                        _standaloneDeclaration = standaloneAttribute.Equals("yes", StringComparison.OrdinalIgnoreCase);
                    }
                }

                if (!xmlReader.EOF)
                {
                    xmlReader.MoveToContent();
                }

                if (xmlReader.EOF ||
                    xmlReader.NodeType != XmlNodeType.Element ||
                    !xmlReader.IsStartElement())
                {
                    //the stream does NOT contains any xml element.
                    return(false);
                }

                var qname = new OpenXmlQualifiedName(xmlReader.NamespaceURI, xmlReader.LocalName);
                if (!qname.Namespace.IsKnown || !QName.Equals(qname))
                {
                    var elementQName = new XmlQualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI).ToString();
                    var msg          = SR.Format(ExceptionMessages.Fmt_PartRootIsInvalid, elementQName, XmlQualifiedName.ToString());

                    throw new InvalidDataException(msg);
                }

                // remove all children and clear all attributes
                OuterXml = string.Empty;
                var mcContextPushed = PushMcContext(xmlReader);
                Load(xmlReader, context.LoadMode);
                if (mcContextPushed)
                {
                    PopMcContext();
                }
            }

            return(true);
        }