public static void ChangeNamespace(XElement element, XmlNamespace ns) { if (ns.Uri != "") element.Name = "{" + ns.Uri + "}" + element.Name.LocalName; else element.Name = element.Name.LocalName; }
/// <summary> /// Gets the element namespace from the element start tag /// string. /// </summary> /// <param name="xml">This string must start at the /// element we are interested in.</param> static Dictionary <string, XmlNamespace> FindAvailableElementNamespace(string xml) { Dictionary <string, XmlNamespace> namespaceDictionary = new Dictionary <string, XmlNamespace>(); XmlNamespace namespaceUri = new XmlNamespace(); Regex regex = new Regex(".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]"); foreach (Match match in regex.Matches(xml)) { if (match.Success) { namespaceUri.Name = match.Groups[2].Value; string xmlns = match.Groups[1].Value.Trim(); int prefixIndex = xmlns.IndexOf(':'); if (prefixIndex > 0) { namespaceUri.Prefix = xmlns.Substring(prefixIndex + 1); } namespaceDictionary.Add(namespaceUri.Prefix, namespaceUri); } } return(namespaceDictionary); }
/// <summary> /// Gets the element namespace from the element start tag /// string. /// </summary> /// <param name="xml">This string must start at the /// element we are interested in.</param> static XmlNamespace GetElementNamespace(string xml) { XmlNamespace namespaceUri = new XmlNamespace(); Match match = Regex.Match(xml, ".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]"); if (match.Success) { namespaceUri.Name = match.Groups[2].Value; string xmlns = match.Groups[1].Value.Trim(); int prefixIndex = xmlns.IndexOf(':'); if (prefixIndex > 0) { namespaceUri.Prefix = xmlns.Substring(prefixIndex + 1); } } return namespaceUri; }
/// <summary> /// Reads the SOAP fault. /// </summary> /// <param name="reader">The reader.</param> /// <returns>SOAP fault details.</returns> protected SoapFaultDetails ReadSoapFault(EwsServiceXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { this.ReadXmlDeclaration(reader); reader.Read(); if (!reader.IsStartElement() || (reader.LocalName != XmlElementNames.SOAPEnvelopeElementName)) { return(soapFaultDetails); } // EWS can sometimes return SOAP faults using the SOAP 1.2 namespace. Get the // namespace URI from the envelope element and use it for the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri); if (soapNamespace == XmlNamespace.NotSpecified) { return(soapFaultDetails); } reader.Read(); // EWS doesn't always return a SOAP header. If this response contains a header element, // read the server version information contained in the header. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.Read(); if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ServerVersionInfo)) { this.Service.ServerInfo = ExchangeServerInfo.Parse(reader); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.Read(); } // Parse the fault element contained within the SOAP body. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.Read(); // Parse Fault element if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.Parse(reader, soapNamespace); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.ReadEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (XmlException) { // If response doesn't contain a valid SOAP fault, just ignore exception and // return null for SOAP fault details. } return(soapFaultDetails); }
/// <summary> /// Determines whether current element is a end element. /// </summary> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="localName">Name of the local.</param> /// <returns> /// <c>true</c> if current element is an end element; otherwise, <c>false</c>. /// </returns> public bool IsEndElement(XmlNamespace xmlNamespace, string localName) { return((this.LocalName == localName) && (this.NodeType == XmlNodeType.EndElement) && ((this.NamespacePrefix == EwsUtilities.GetNamespacePrefix(xmlNamespace)) || (this.NamespaceUri == EwsUtilities.GetNamespaceUri(xmlNamespace)))); }
public bool IsIgnorable(XmlNamespace xmlNamespace) { return(false); }
public void PrefixAndNamespaceToString() { XmlNamespace ns = new XmlNamespace("f", "http://foo.com"); Assert.AreEqual("Prefix [f] Uri [http://foo.com]", ns.ToString()); }
/// <summary> /// Reads the SOAP fault. /// </summary> /// <param name="reader">The reader.</param> /// <returns>SOAP fault details.</returns> private SoapFaultDetails ReadSoapFault(EwsXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { // WCF may not generate an XML declaration. reader.Read(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { reader.Read(); } if (!reader.IsStartElement() || (reader.LocalName != XmlElementNames.SOAPEnvelopeElementName)) { return(soapFaultDetails); } // Get the namespace URI from the envelope element and use it for the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri); if (soapNamespace == XmlNamespace.NotSpecified) { return(soapFaultDetails); } reader.Read(); // Skip SOAP header. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.Read(); }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.Read(); } // Parse the fault element contained within the SOAP body. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.Read(); // Parse Fault element if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.Parse(reader, soapNamespace); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.ReadEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (XmlException) { // If response doesn't contain a valid SOAP fault, just ignore exception and // return null for SOAP fault details. } return(soapFaultDetails); }
public QualifiedName(string name, XmlNamespace ns) : this(name, ns.Name, ns.Prefix) { }
internal static IProperty GetPropertyKey(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlElementReference, string fullPropertyName, XmlNamespace targetTypeNamespace, IType targetTypeId, MemberType memberTypes, MemberType defaultType, bool allowProtectedPropertiesOnTargetType) { XmlnsPrefix prefix; string typeName; if (!XamlTypeHelper.SplitTypeName(parserContext, lineInformation, fullPropertyName, out prefix, out typeName)) { return((IProperty)null); } XmlNamespace xmlNamespace = (XmlNamespace)null; if (prefix != XmlnsPrefix.EmptyPrefix || typeName.IndexOf('.') >= 0) { xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlElementReference, prefix); if (xmlNamespace == null) { return((IProperty)null); } } return(XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespace, typeName, targetTypeNamespace, targetTypeId, memberTypes, defaultType, allowProtectedPropertiesOnTargetType)); }
internal static IType GetTypeId(ITypeResolver typeResolver, ClrNamespaceUriParseCache documentNamespaces, XmlNamespace xmlNamespace, string typeName, bool instantiateUnrecognizedTypes, bool inMarkupExtension) { IType designTimeType = typeResolver.PlatformMetadata.GetDesignTimeType(typeResolver, (IXmlNamespace)xmlNamespace, typeName); if (designTimeType != null) { return(designTimeType); } AssemblyNamespace assemblyNamespace; documentNamespaces.GetNamespace((IXmlNamespace)xmlNamespace, out assemblyNamespace); IType type; if (assemblyNamespace != null) { type = XamlTypeHelper.ResolveType(typeResolver, (IXmlNamespaceTypeResolver)documentNamespaces, xmlNamespace, typeName, inMarkupExtension); if (type == null && instantiateUnrecognizedTypes) { IAssembly assembly = assemblyNamespace.Assembly; string clrNamespace = assemblyNamespace.ClrNamespace; type = typeResolver.GetType(assembly.Name, TypeHelper.CombineNamespaceAndTypeName(clrNamespace, typeName)) ?? typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, assembly, clrNamespace, typeName); } } else { type = XamlTypeHelper.ResolveType(typeResolver, typeResolver.ProjectNamespaces, xmlNamespace, typeName, inMarkupExtension); if (type == null && instantiateUnrecognizedTypes) { type = typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, (IXmlNamespace)xmlNamespace, typeName); } } return(type); }
/// <summary> /// Load failed mailboxes xml /// </summary> /// <param name="rootXmlNamespace">Root xml namespace</param> /// <param name="reader">The reader</param> /// <returns>Array of failed mailboxes</returns> internal static FailedSearchMailbox[] LoadFailedMailboxesXml(XmlNamespace rootXmlNamespace, EwsServiceXmlReader reader) { List<FailedSearchMailbox> failedMailboxes = new List<FailedSearchMailbox>(); reader.EnsureCurrentNodeIsStartElement(rootXmlNamespace, XmlElementNames.FailedMailboxes); do { reader.Read(); if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.FailedMailbox)) { string mailbox = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Mailbox); int errorCode = 0; int.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ErrorCode), out errorCode); string errorMessage = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ErrorMessage); bool isArchive = false; bool.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.IsArchive), out isArchive); failedMailboxes.Add(new FailedSearchMailbox(mailbox, errorCode, errorMessage, isArchive)); } } while (!reader.IsEndElement(rootXmlNamespace, XmlElementNames.FailedMailboxes)); return failedMailboxes.Count == 0 ? null : failedMailboxes.ToArray(); }
internal static IType GetTypeId(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName, bool inMarkupExtension) { if (string.IsNullOrEmpty(typeName)) { parserContext.ReportError(XamlParseErrors.MissingTypeName(lineInformation)); return((IType)null); } if (typeName.IndexOf('.') >= 0) { parserContext.ReportError(XamlParseErrors.InnerTypesNotSupported(lineInformation, typeName)); return((IType)null); } IType typeId = XamlTypeHelper.GetTypeId(parserContext.TypeResolver, parserContext.DocumentNamespaces, xmlNamespace, typeName, true, inMarkupExtension); if (typeId != null && typeId.IsResolvable) { if (!parserContext.TypeResolver.InTargetAssembly(typeId) && !TypeHelper.IsSet(MemberAccessTypes.Public, typeId.Access)) { parserContext.ReportError(XamlParseErrors.InaccessibleType(lineInformation, typeName)); return((IType)null); } } else if (xmlNamespace == XmlNamespace.AvalonXmlNamespace || xmlNamespace == XmlNamespace.XamlXmlNamespace) { parserContext.ReportError(XamlParseErrors.UnrecognizedPlatformTypeName(lineInformation, !parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IsWpf), typeName)); } else { parserContext.ReportError(XamlParseErrors.UnrecognizedTypeName(lineInformation, xmlNamespace, typeName)); } return(typeId); }
internal static IProperty GetPropertyKey(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeAndPropertyName, XmlNamespace targetTypeNamespace, IType targetTypeId, MemberType memberTypes, MemberType defaultType, bool allowProtectedPropertiesOnTargetType) { string typeName; string memberName; if (XamlTypeHelper.SplitMemberName(parserContext, lineInformation, typeAndPropertyName, out typeName, out memberName)) { if (string.IsNullOrEmpty(memberName)) { parserContext.ReportError(XamlParseErrors.MissingArgumentName(lineInformation)); return((IProperty)null); } if (xmlNamespace == XmlNamespace.DesignTimeXmlNamespace) { return(parserContext.PlatformMetadata.GetDesignTimeProperty(memberName, targetTypeId)); } if (xmlNamespace != null && typeName == null) { if (xmlNamespace == XmlNamespace.XamlXmlNamespace) { IProperty property = XamlProcessingAttributes.GetProperty(memberName, parserContext.TypeResolver.PlatformMetadata); if (property != null) { return(property); } parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName)); return((IProperty)null); } if (xmlNamespace == XmlNamespace.PresentationOptionsXmlNamespace) { if (memberName == parserContext.PlatformMetadata.KnownProperties.DesignTimeFreeze.Name) { return(parserContext.TypeResolver.ResolveProperty(parserContext.PlatformMetadata.KnownProperties.DesignTimeFreeze)); } parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName)); return((IProperty)null); } if (targetTypeNamespace == null || !xmlNamespace.Equals((object)targetTypeNamespace)) { parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName)); return((IProperty)null); } } MemberAccessTypes access = MemberAccessTypes.None; if (typeName != null) { if (xmlNamespace != null) { targetTypeId = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName); if (parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId)) { return((IProperty)null); } access = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, targetTypeId); } } else if (!parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId)) { access = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, targetTypeId); if (allowProtectedPropertiesOnTargetType) { access |= MemberAccessTypes.Protected; } } if (!parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId)) { IProperty property1 = (IProperty)targetTypeId.GetMember(defaultType, memberName, access); if (property1 == null) { MemberType memberTypes1 = memberTypes & ~defaultType; if (memberTypes1 != MemberType.None) { property1 = (IProperty)targetTypeId.GetMember(memberTypes1, memberName, access); } } if (property1 == null && targetTypeId.PlatformMetadata.GetProxyProperties(parserContext.TypeResolver) != null) { foreach (IProperty property2 in targetTypeId.PlatformMetadata.GetProxyProperties(parserContext.TypeResolver)) { if (memberName == property2.Name && property2.DeclaringType.IsAssignableFrom((ITypeId)targetTypeId) && TypeHelper.IsSet(memberTypes, property2.MemberType)) { property1 = property2; break; } } } if (property1 == null) { property1 = (IProperty)XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, targetTypeId, defaultType, memberName); } if (property1 == null) { parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName)); } return(property1); } parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName)); } return((IProperty)null); }
internal static IType GetTypeId(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName) { return(XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName, false)); }
private static IType ResolveType(ITypeResolver typeResolver, IXmlNamespaceTypeResolver xmlNamespaceTypeResolver, XmlNamespace xmlNamespace, string typeName, bool inMarkupExtension) { return(XamlTypeHelper.ResolveTypeInternal(typeResolver, xmlNamespaceTypeResolver, xmlNamespace, inMarkupExtension ? typeName + "Extension" : typeName) ?? XamlTypeHelper.ResolveTypeInternal(typeResolver, xmlNamespaceTypeResolver, xmlNamespace, inMarkupExtension ? typeName : typeName + "Extension")); }
/// <summary> /// Hash on all name components. /// </summary> public override int GetHashCode() { return(XmlNamespace.GetHashCode() ^ BaseName.GetHashCode()); }
private static bool IsTypeInXmlNamespace(IProjectContext project, IType type, string xmlNamespaceString) { if (project == null || project.ProjectNamespaces == null) { return(false); } IXmlNamespace @namespace = project.ProjectNamespaces.GetNamespace(type.RuntimeAssembly, type.Namespace); IXmlNamespace xmlNamespace = (IXmlNamespace)XmlNamespace.ToNamespace(xmlNamespaceString, XmlNamespace.GetNamespaceCanonicalization((ITypeResolver)project)); return(@namespace != null && @namespace.Value == xmlNamespace.Value); }
private static IType ResolveTypeInternal(ITypeResolver typeResolver, IXmlNamespaceTypeResolver xmlNamespaceTypeResolver, XmlNamespace xmlNamespace, string typeName) { IType type = xmlNamespaceTypeResolver.GetType((IXmlNamespace)xmlNamespace, typeName); if (type == null && xmlNamespace == XmlNamespace.DesignTimeXmlNamespace) { type = typeResolver.PlatformMetadata.GetDesignTimeType(typeResolver, (IXmlNamespace)xmlNamespace, typeName); } return(type); }
public static void WriteNamespace(this XmlWriter writer, XmlNamespace ns) { writer.WriteAttributeString("xmlns", ns.Prefix, null, ns.NamespaceUri); }
internal bool IsDefaultNamespace(IXmlNamespace xmlNamespace) { XmlNamespace xmlNamespace1 = (XmlNamespace)this.TypeResolver.GetCapabilityValue(PlatformCapability.DefaultXmlns); return(xmlNamespace == xmlNamespace1); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="xmlElementName">Name of the XML element.</param> internal override void LoadFromXml( EwsServiceXmlReader reader, XmlNamespace xmlNamespace, string xmlElementName) { base.LoadFromXml(reader, xmlNamespace, xmlElementName); this.AdjustPermissionLevel(); }
public void Init() { lhs = new XmlNamespace(); rhs = new XmlNamespace(); }
public void Init() { path = new XmlElementPath(); fooNamespace = new XmlNamespace("foo", "http://foo"); barNamespace = new XmlNamespace("bar", "http://bar"); }
public void HasNamePropertyReturnsFalseWhenNamespaceIsEmptyString() { XmlNamespace ns = new XmlNamespace("s", String.Empty); Assert.IsFalse(ns.HasName); }
/// <summary> /// Determines whether current element is a start element. /// </summary> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="localName">Name of the local.</param> /// <returns> /// <c>true</c> if current element is a start element; otherwise, <c>false</c>. /// </returns> public bool IsStartElement(XmlNamespace xmlNamespace, string localName) { return((this.LocalName == localName) && this.IsStartElement() && ((this.NamespacePrefix == EwsUtilities.GetNamespacePrefix(xmlNamespace)) || (this.NamespaceUri == EwsUtilities.GetNamespaceUri(xmlNamespace)))); }
public void HasNamePropertyReturnsTrueWhenNamespaceIsNotEmptyString() { XmlNamespace ns = new XmlNamespace("s", "ns"); Assert.IsTrue(ns.HasName); }
/// <summary> /// Reads to the next descendant element with the specified local name and namespace. /// </summary> /// <param name="xmlNamespace">The namespace of the element you with to move to.</param> /// <param name="localName">The local name of the element you wish to move to.</param> public void ReadToDescendant(XmlNamespace xmlNamespace, string localName) { this.xmlReader.ReadToDescendant(localName, EwsUtilities.GetNamespaceUri(xmlNamespace)); }
public void Init() { xmlNamespace = new XmlNamespace("xml", "http://www.w3.org/XML/1998/namespace"); }
public static ITypeId SniffRootNodeType(Stream stream, IDocumentContext documentContext, out string xamlClassAttribute) { xamlClassAttribute = (string)null; try { ITypeResolver typeResolver = documentContext.TypeResolver; using (XmlReader xmlReader = XmlReader.Create(stream)) { ClrNamespaceUriParseCache documentNamespaces = new ClrNamespaceUriParseCache(typeResolver); while (xmlReader.Read()) { if (xmlReader.MoveToContent() == XmlNodeType.Element) { xamlClassAttribute = xmlReader.GetAttribute("Class", "http://schemas.microsoft.com/winfx/2006/xaml"); string str = xmlReader.LookupNamespace(xmlReader.Prefix); if (!string.IsNullOrEmpty(str)) { return((ITypeId)XamlTypeHelper.GetTypeId(typeResolver, documentNamespaces, XmlNamespace.ToNamespace(str, XmlNamespace.GetNamespaceCanonicalization(typeResolver)), xmlReader.LocalName, false, false)); } } } } } catch (XmlException ex) { } return((ITypeId)null); }
/// <summary> /// Reads the element value as date time. /// </summary> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="localName">Name of the local.</param> /// <returns>Element value.</returns> public DateTime?ReadElementValueAsDateTime(XmlNamespace xmlNamespace, string localName) { return(this.ConvertStringToDateTime(this.ReadElementValue(xmlNamespace, localName))); }
public static XamlParseError UnrecognizedTypeName(ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName) { return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedTypeName, lineInformation, StringTable.ParserUnrecognizedTypeName, xmlNamespace.Value, typeName)); }
public ICodeAidTypeInfo GetTypeByName(string uri, string typeName) { IProjectContext projectContext = this.ProjectContext; IXmlNamespace xmlNamespace = (IXmlNamespace)XmlNamespace.ToNamespace(uri, XmlNamespace.GetNamespaceCanonicalization((ITypeResolver)projectContext)); if (xmlNamespace == null) { return((ICodeAidTypeInfo)null); } IType type = projectContext.GetType(xmlNamespace, typeName); if (type != null) { return((ICodeAidTypeInfo) new CodeAidTypeInfo(this, type)); } return((ICodeAidTypeInfo)null); }
public void SimpleNamespace() { XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com"); Assert.AreEqual("s", ns.Prefix); Assert.AreEqual("http://sharpdevelop.com", ns.Uri); }
internal static bool IsIgnorable(XamlParserContext parserContext, IXmlNamespaceResolver xmlNamespaceResolver, XmlNamespace xmlNamespace) { if (xmlNamespace == XmlNamespace.DesignTimeXmlNamespace || xmlNamespace == XmlNamespace.AnnotationsXmlNamespace || (!xmlNamespaceResolver.IsIgnorable(xmlNamespace) || parserContext.TypeResolver.ProjectNamespaces.Contains((IXmlNamespace)xmlNamespace))) { return(false); } AssemblyNamespace assemblyNamespace; parserContext.DocumentNamespaces.GetNamespace((IXmlNamespace)xmlNamespace, out assemblyNamespace); return(assemblyNamespace == null); }