示例#1
0
        /// <summary>
        /// Get the expected elements - elements which minOccurs >= 0.
        /// </summary>
        /// <param name="result"></param>
        /// <returns>True if there are expected elements in this particle.</returns>
        public override bool GetExpectedElements(ExpectedChildren result)
        {
            if (result != null)
            {
                result.Add(NamespaceIdMap.GetNamespaceUri(this._nsAnyParticleConstraint.NamespaceId));
            }

            return(true);
        }
        /// <summary>
        /// Get the required elements - elements which minOccurs > 0.
        /// </summary>
        /// <param name="result"></param>
        /// <returns>True if there are required elements in this particle.</returns>
        public override bool GetRequiredElements(ExpectedChildren result)
        {
            if (ParticleConstraint.MinOccurs > 0)
            {
                if (result != null)
                {
                    result.Add(NamespaceIdMap.GetNamespaceUri(_nsAnyParticleConstraint.NamespaceId));
                }

                return(true);
            }
            return(false);
        }
        public void NamespacePrefixTest(string ns, string prefix, FileFormatVersions version, byte id)
        {
            Assert.True(NamespaceIdMap.TryGetNamespaceId(ns, out var outId));
            Assert.Equal(id, outId);

            Assert.Equal(prefix, NamespaceIdMap.GetNamespacePrefix(id));

            Assert.Equal(ns, NamespaceIdMap.GetNamespaceUri(prefix));
            Assert.Equal(ns, NamespaceIdMap.GetNamespaceUri(id));

            foreach (var v in FileFormatVersionExtensions.AllVersions)
            {
                Assert.Equal(v == version, NamespaceIdMap.IsInFileFormat(ns, v));
            }
        }
        private int GetIndex(string namespaceUri, string tagName)
        {
            if (!string.IsNullOrEmpty(tagName) && NamespaceIdMap.TryGetNamespaceId(namespaceUri, out var nsId))
            {
                for (var i = 0; i < _attributes.Length; i++)
                {
                    var tag = _attributes[i];

                    if (tag.Name.Equals(tagName, StringComparison.Ordinal) && tag.NamespaceId == nsId)
                    {
                        return(i);
                    }
                }
            }

            return(-1);
        }
示例#5
0
        /// <summary>
        /// Try match this element once.
        /// </summary>
        /// <param name="particleMatchInfo"></param>
        /// <param name="validationContext">The context information for validation.</param>
        public override void TryMatchOnce(ParticleMatchInfo particleMatchInfo, ValidationContext validationContext)
        {
            Debug.Assert(particleMatchInfo != null);
            Debug.Assert(particleMatchInfo.StartElement != null);
            Debug.Assert(!(particleMatchInfo.StartElement is OpenXmlMiscNode));

            var element = particleMatchInfo.StartElement;

            if (element.NamespaceUri == NamespaceIdMap.GetNamespaceUri(this._nsAnyParticleConstraint.NamespaceId))
            {
                particleMatchInfo.Match = ParticleMatch.Matched;
                particleMatchInfo.LastMatchedElement = element;
            }
            else
            {
                particleMatchInfo.Match = ParticleMatch.Nomatch;
            }
            return;
        }
        /// <summary>
        /// This method fills the collection with PackageRels from the PackageRelationshipCollection that is given in the sub class.
        /// </summary>
        protected void Build()
        {
            foreach (PackageRelationship relationship in BasePackageRelationshipCollection)
            {
                RelationshipProperty relationshipProperty;

                relationshipProperty.TargetUri        = relationship.TargetUri;
                relationshipProperty.TargetMode       = relationship.TargetMode;
                relationshipProperty.Id               = relationship.Id;
                relationshipProperty.RelationshipType = relationship.RelationshipType;

                // If packageRel.RelationshipType is something for Strict, it tries to get the equivalent in Transitional.
                if (NamespaceIdMap.TryGetTransitionalRelationship(relationshipProperty.RelationshipType, out var transitionalNamespace))
                {
                    relationshipProperty.RelationshipType = transitionalNamespace;
                    StrictRelationshipFound = true;
                }

                Add(relationshipProperty);
            }
        }
示例#7
0
        /// <summary>
        /// This method fills the collection with PackageRels from the PackageRelationshipCollection that is given in the sub class.
        /// </summary>
        protected void Build()
        {
            foreach (PackageRelationship relationship in this.BasePackageRelationshipCollection)
            {
                bool   found;
                string transitionalNamespace;
                RelationshipProperty relationshipProperty;

                relationshipProperty.TargetUri        = relationship.TargetUri;
                relationshipProperty.TargetMode       = relationship.TargetMode;
                relationshipProperty.Id               = relationship.Id;
                relationshipProperty.RelationshipType = relationship.RelationshipType;

                // If packageRel.RelationshipType is something for Strict, it tries to get the equivalent in Transitional.
                found = NamespaceIdMap.TryGetTransitionalRelationship(relationshipProperty.RelationshipType, out transitionalNamespace);
                if (found)
                {
                    relationshipProperty.RelationshipType = transitionalNamespace;
                    this.StrictTranslation = true;
                }

                this.Add(relationshipProperty);
            }
        }
示例#8
0
 public void SetSchema(string ns, string localName)
 => SetSchema(NamespaceIdMap.GetNamespaceId(ns), localName);
 public void TryGetNamespaceIdFails(string ns)
 {
     Assert.False(NamespaceIdMap.TryGetNamespaceId(ns, out var id));
     Assert.Equal(byte.MaxValue, id);
 }
 protected static XmlQualifiedName GetAttributeQualifiedName(OpenXmlElement element, byte attributeID)
 {
     return(new XmlQualifiedName(element.AttributeTagNames[attributeID], NamespaceIdMap.GetNamespaceUri(element.AttributeNamespaceIds[attributeID])));
 }