internal OpenXmlCompositeElement GetContentFromACBlock(AlternateContent acblk, FileFormatVersions format) { Debug.Assert(format != (FileFormatVersions.Office2007 | FileFormatVersions.Office2010 | FileFormatVersions.Office2013)); foreach (var choice in acblk.ChildElements.OfType <AlternateContentChoice>()) { if (choice.Requires == null) { //should we throw exception here? continue; } string reqs = choice.Requires.InnerText.Trim(); if (string.IsNullOrEmpty(reqs)) { //should we throw exception here? continue; } bool chooce = true; foreach (var req in reqs.Split(new char[] { ' ' })) { //fix bug 537858 //the LookupNamespaceDeleget is from xmlReader //bug when we try to GetContentFromACBlock, the reader has already moved to the next element of ACB //so we should use the element's LookupNamespace function to find it //string ns = LookupNamespaceDelegate(req); string ns = choice.LookupNamespace(req); if (ns == null) { if (this._noExceptionOnError) { chooce = false; break; } else { var msg = String.Format(System.Globalization.CultureInfo.CurrentUICulture, ExceptionMessages.UnknowMCContent, req); throw new InvalidMCContentException(msg); } } if (!NamespaceIdMap.IsInFileFormat(ns, format)) { chooce = false; break; } } if (chooce) { return(choice); } } var fallback = acblk.GetFirstChild <AlternateContentFallback>(); if (fallback != null) { return(fallback); } return(null); }
/// <summary> /// Initializes a new instance of the SchemaAttrAttribute. /// </summary> /// <param name="nsId">Specifies the Namespace Id of the schema attribute.</param> /// <param name="tag">Specifies the Tag name of the schema attribute.</param> public SchemaAttrAttribute(byte nsId, string tag) { if (string.IsNullOrEmpty(tag)) { throw new ArgumentNullException(nameof(tag)); } NamespaceUri = NamespaceIdMap.GetNamespaceUri(nsId); Tag = tag; }
internal bool IsIgnorableNs(byte namespaceId) { if (_currentIgnorable.Count == 0) { return(false); } if (_currentIgnorable.Contains(NamespaceIdMap.GetNamespaceUri(namespaceId))) { return(true); } else { return(false); } }
private OpenXmlElement CreateElement(string namespaceUri, string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException(nameof(name)); } if (NamespaceIdMap.TryGetNamespaceId(namespaceUri, out byte nsId) && PackageCache.Cache.ParseElement(GetType()).SchemaLookup.Create(nsId, name) is OpenXmlElement element) { return(element); } // return unknown element instead of throw exception. return(new OpenXmlUnknownElement()); }
private int GetIndex(string namespaceUri, string tagName) { if (!string.IsNullOrEmpty(tagName) && namespaceUri != null && NamespaceIdMap.TryGetNamespaceId(namespaceUri, out var nsId)) { for (var i = 0; i < _tags.Length; i++) { var tag = _tags[i]; if (tag.Name.Equals(tagName, StringComparison.Ordinal) && tag.NamespaceId == nsId) { return(i); } } } return(-1); }
internal static OpenXmlElement CreateElement(string namespaceUri, string name) { // Debug.Assert(namespaceUri != null); Debug.Assert(!string.IsNullOrEmpty(name)); OpenXmlElement newElement = null; byte nsId; if ((namespaceUri != null) && NamespaceIdMap.TryGetNamespaceId(namespaceUri, out nsId)) { newElement = CreateElement(nsId, name); } if (newElement == null) { // return unknown element instead of throw exception. newElement = new OpenXmlUnknownElement(); } return(newElement); }