//This method processes the attributes that are present on the Relationship element private void ProcessRelationshipAttributes(XmlCompatibilityReader reader) { // Attribute : TargetMode string?targetModeAttributeValue = reader.GetAttribute(TargetModeAttributeName); //If the TargetMode attribute is missing in the underlying markup then we assume it to be internal TargetMode relationshipTargetMode = TargetMode.Internal; if (targetModeAttributeValue != null) { try { #if NET6_0_OR_GREATER relationshipTargetMode = Enum.Parse <TargetMode>(targetModeAttributeValue, ignoreCase: false); #else relationshipTargetMode = (TargetMode)(Enum.Parse(typeof(TargetMode), targetModeAttributeValue, ignoreCase: false)); #endif } catch (ArgumentNullException argNullEx) { ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argNullEx); } catch (ArgumentException argEx) { //if the targetModeAttributeValue is not Internal|External then Argument Exception will be thrown. ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argEx); } } // Attribute : Target // create a new PackageRelationship string?targetAttributeValue = reader.GetAttribute(TargetAttributeName); if (string.IsNullOrEmpty(targetAttributeValue)) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TargetAttributeName), null, reader.LineNumber, reader.LinePosition); } Uri targetUri = new Uri(targetAttributeValue, DotNetRelativeOrAbsolute); // Attribute : Type string?typeAttributeValue = reader.GetAttribute(TypeAttributeName); if (string.IsNullOrEmpty(typeAttributeValue)) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TypeAttributeName), null, reader.LineNumber, reader.LinePosition); } // Attribute : Id // Get the Id attribute (required attribute). string?idAttributeValue = reader.GetAttribute(IdAttributeName); if (string.IsNullOrEmpty(idAttributeValue)) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, IdAttributeName), null, reader.LineNumber, reader.LinePosition); } // Add the relationship to the collection Add(targetUri, relationshipTargetMode, typeAttributeValue, idAttributeValue, parsing: true); }
// Token: 0x06002E76 RID: 11894 RVA: 0x000D289C File Offset: 0x000D0A9C private static string _ConstructPageString(Stream pageStream, bool reverseRTL) { XmlTextReader baseReader = new XmlTextReader(pageStream); XmlReader xmlReader = new XmlCompatibilityReader(baseReader, FixedFindEngine._predefinedNamespaces); xmlReader = XmlReader.Create(xmlReader, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true, ProhibitDtd = true }); xmlReader.MoveToContent(); StringBuilder stringBuilder = new StringBuilder(); bool flag = false; string text = null; while (xmlReader.Read()) { XmlNodeType nodeType = xmlReader.NodeType; if (nodeType == XmlNodeType.Element && xmlReader.Name == "Glyphs") { text = xmlReader.GetAttribute("UnicodeString"); if (!string.IsNullOrEmpty(text)) { string attribute = xmlReader.GetAttribute("IsSideways"); flag = false; if (attribute != null && string.Compare(attribute, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0) { flag = true; } if (reverseRTL) { string attribute2 = xmlReader.GetAttribute("BidiLevel"); int num = 0; if (!string.IsNullOrEmpty(attribute2)) { try { num = Convert.ToInt32(attribute2, CultureInfo.InvariantCulture); } catch (Exception) { } } string attribute3 = xmlReader.GetAttribute("CaretStops"); if (num == 0 && !flag && string.IsNullOrEmpty(attribute3) && FixedTextBuilder.MostlyRTL(text)) { char[] array = text.ToCharArray(); Array.Reverse(array); text = new string(array); } } stringBuilder.Append(text); } } } return(stringBuilder.ToString()); }
//This method processes the attributes that are present on the Relationship element private void ProcessRelationshipAttributes(XmlCompatibilityReader reader) { // Attribute : TargetMode string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName); //If the TargetMode attribute is missing in the underlying markup then we assume it to be internal TargetMode relationshipTargetMode = TargetMode.Internal; if (targetModeAttributeValue != null) { try { relationshipTargetMode = (TargetMode)(Enum.Parse(typeof(TargetMode), targetModeAttributeValue, false /* ignore case */)); } catch (ArgumentNullException argNullEx) { ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argNullEx); } catch (ArgumentException argEx) { //if the targetModeAttributeValue is not Internal|External then Argument Exception will be thrown. ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argEx); } } // Attribute : Target // create a new PackageRelationship string targetAttributeValue = reader.GetAttribute(s_targetAttributeName); if (targetAttributeValue == null || targetAttributeValue == String.Empty) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_targetAttributeName), null, reader.LineNumber, reader.LinePosition); } Uri targetUri = new Uri(targetAttributeValue, UriKind.RelativeOrAbsolute); // Attribute : Type string typeAttributeValue = reader.GetAttribute(s_typeAttributeName); if (typeAttributeValue == null || typeAttributeValue == String.Empty) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_typeAttributeName), null, reader.LineNumber, reader.LinePosition); } // Attribute : Id // Get the Id attribute (required attribute). string idAttributeValue = reader.GetAttribute(s_idAttributeName); if (idAttributeValue == null || idAttributeValue == String.Empty) { throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_idAttributeName), null, reader.LineNumber, reader.LinePosition); } // Add the relationship to the collection Add(targetUri, relationshipTargetMode, typeAttributeValue, idAttributeValue, true /*parsing*/); }
//Throws an exception if the xml:base attribute is present in the Relationships XML private void ThrowIfXmlBaseAttributeIsPresent(XmlCompatibilityReader reader) { string xmlBaseAttributeValue = reader.GetAttribute(s_xmlBaseAttributeName); if (xmlBaseAttributeValue != null) { throw new XmlException(SR.Format(SR.InvalidXmlBaseAttributePresent, s_xmlBaseAttributeName), null, reader.LineNumber, reader.LinePosition); } }
/// <summary> /// Parse PackageRelationship Stream /// </summary> /// <param name="part">relationship part</param> /// <exception cref="XmlException">Thrown if XML is malformed</exception> private void ParseRelationshipPart(PackagePart part) { //We can safely open the stream as FileAccess.Read, as this code //should only be invoked if the Package has been opened in Read or ReadWrite mode. Debug.Assert(_package.FileOpenAccess == FileAccess.Read || _package.FileOpenAccess == FileAccess.ReadWrite, "This method should only be called when FileAccess is Read or ReadWrite"); using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read)) { // load from the relationship part associated with the given part using (XmlReader baseReader = XmlReader.Create(s)) { using (XmlCompatibilityReader reader = new XmlCompatibilityReader(baseReader, s_relationshipKnownNamespaces)) { //This method expects the reader to be in ReadState.Initial. //It will make the first read call. PackagingUtilities.PerformInitialReadAndVerifyEncoding(baseReader); //Note: After the previous method call the reader should be at the first tag in the markup. //MoveToContent - Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace //If the reader is currently at a content node then this function call is a no-op reader.MoveToContent(); // look for our tag and namespace pair - throw if other elements are encountered // Make sure that the current node read is an Element if (reader.NodeType == XmlNodeType.Element && (reader.Depth == 0) && (String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0) && (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0)) { ThrowIfXmlBaseAttributeIsPresent(reader); //There should be a namespace Attribute present at this level. //Also any other attribute on the <Relationships> tag is an error including xml: and xsi: attributes if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 0) { throw new XmlException(SR.RelationshipsTagHasExtraAttributes, null, reader.LineNumber, reader.LinePosition); } // start tag encountered for Relationships // now parse individual Relationship tags while (reader.Read()) { //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace //If the reader is currently at a content node then this function call is a no-op reader.MoveToContent(); //If MoveToContent() takes us to the end of the content if (reader.NodeType == XmlNodeType.None) { continue; } if (reader.NodeType == XmlNodeType.Element && (reader.Depth == 1) && (String.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0) && (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0)) { ThrowIfXmlBaseAttributeIsPresent(reader); int expectedAttributesCount = 3; string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName); if (targetModeAttributeValue != null) { expectedAttributesCount++; } //check if there are expected number of attributes. //Also any other attribute on the <Relationship> tag is an error including xml: and xsi: attributes if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) == expectedAttributesCount) { ProcessRelationshipAttributes(reader); //Skip the EndElement for Relationship if (!reader.IsEmptyElement) { ProcessEndElementForRelationshipTag(reader); } } else { throw new XmlException(SR.RelationshipTagDoesntMatchSchema, null, reader.LineNumber, reader.LinePosition); } } else if (!(String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0 && (reader.NodeType == XmlNodeType.EndElement))) { throw new XmlException(SR.UnknownTagEncountered, null, reader.LineNumber, reader.LinePosition); } } } else { throw new XmlException(SR.ExpectedRelationshipsElementTag, null, reader.LineNumber, reader.LinePosition); } } } } }
private static String _ConstructPageString(Stream pageStream, bool reverseRTL) { Debug.Assert(pageStream != null); XmlTextReader xmlTextReader = new XmlTextReader(pageStream); //Wrap around a compatibility reader XmlReader xmlReader = new XmlCompatibilityReader(xmlTextReader, _predefinedNamespaces); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; settings.ProhibitDtd = true; xmlReader = XmlReader.Create(xmlReader, settings); xmlReader.MoveToContent(); StringBuilder pageString = new StringBuilder(); bool isSideways = false; string unicodeStr = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: { if (xmlReader.Name == "Glyphs") { unicodeStr = xmlReader.GetAttribute("UnicodeString"); if (!String.IsNullOrEmpty(unicodeStr)) { string sidewaysString = xmlReader.GetAttribute("IsSideways"); isSideways = false; if (sidewaysString != null && String.Compare(sidewaysString, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0) { isSideways = true; } if (reverseRTL) { //This is to cover for MXDW generation //RTL Glyphs are saved LTR and bidi level is not set //In this case we need to reverse the UnicodeString string bidiLevelAsString = xmlReader.GetAttribute("BidiLevel"); int bidiLevel = 0; if (!String.IsNullOrEmpty(bidiLevelAsString)) { try { bidiLevel = Convert.ToInt32(bidiLevelAsString, CultureInfo.InvariantCulture); } catch (Exception) { } } string caretStops = xmlReader.GetAttribute("CaretStops"); if (bidiLevel == 0 && !isSideways && String.IsNullOrEmpty(caretStops) && FixedTextBuilder.MostlyRTL(unicodeStr)) { char[] chars = unicodeStr.ToCharArray(); Array.Reverse(chars); unicodeStr = new String(chars); } } pageString.Append(unicodeStr); } } } break; } } return(pageString.ToString()); }