Beispiel #1
0
 /// <summary>
 /// 对 本结点(xNode) 的 Namespace 注册
 /// </summary>
 /// <param name="xNode">含有或继承有命名空间的结点</param>
 /// <param name="xNameSpaceManager">命名空间管理器</param>
 /// <returns>返回该 Namespace 的 prefix</returns>
 public static string AutoPrefix(System.Xml.XmlNode xNode, System.Xml.XmlNamespaceManager xNameSpaceManager)
 {
     string xPrefix;
     if (xNode.NamespaceURI == string.Empty)
     {
         return string.Empty;
     }
     else
     {
         xPrefix = xNameSpaceManager.LookupPrefix(xNode.NamespaceURI);
         if (xPrefix == null || xPrefix == string.Empty)
         {
             xPrefix = "x" + xNode.GetHashCode().ToString();
             xNameSpaceManager.AddNamespace(xPrefix, xNode.NamespaceURI);
         }
         return xPrefix + (xPrefix.Length > 0 ? ":" : "");
     }
 }
 public void Write(
     System.Xml.XmlWriter xmlWriter,
     ResourceStatus resourceStatus
     )
 {
     if (resourceStatus == ResourceStatus.Unknown)
         return;
     if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP11NamespaceUri)))
         xmlWriter.WriteAttributeString
             (
             "recstatus",
             ((int)resourceStatus).ToString()
             );
     else
         xmlWriter.WriteAttributeString
             (
             "recstatus",
             Configuration.Namespaces.XCRICAP11NamespaceUri,
             ((int)resourceStatus).ToString()
             );
 }
 public virtual void Write(
     System.Xml.XmlWriter xmlWriter,
     XCRI.Interfaces.XCRICAP12.IImage image
     )
 {
     if (image == null)
         throw new ArgumentNullException("image");
     if ((image.CompatibleWith & XCRIProfiles.XCRI_v1_2) == 0)
         return;
     this._WriteStartElement(xmlWriter, "image", Configuration.Namespaces.XCRICAP12NamespaceUri);
     this._WriteXsiTypeAttribute(xmlWriter, image.XsiTypeValue, image.XsiTypeValueNamespace);
     this._WriteXmlLanguageAttribute(xmlWriter, image.XmlLanguage);
     if (image.Source != null)
         if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP11NamespaceUri)))
             xmlWriter.WriteAttributeString("src", image.Source.ToString());
         else
             xmlWriter.WriteAttributeString("src", Configuration.Namespaces.XCRICAP11NamespaceUri, image.Source.ToString());
     if (String.IsNullOrEmpty(image.Title) == false)
         if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP11NamespaceUri)))
             xmlWriter.WriteAttributeString("title", image.Title);
         else
             xmlWriter.WriteAttributeString("title", Configuration.Namespaces.XCRICAP11NamespaceUri, image.Title);
     if (String.IsNullOrEmpty(image.Alt) == false)
         if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP11NamespaceUri)))
             xmlWriter.WriteAttributeString("alt", image.Alt);
         else
             xmlWriter.WriteAttributeString("alt", Configuration.Namespaces.XCRICAP11NamespaceUri, image.Alt);
     this._WriteEndElement(xmlWriter);
 }
 public virtual void Write(
     System.Xml.XmlWriter xmlWriter,
     XCRI.Interfaces.XCRICAP12.ICatalog catalog
     )
 {
     if (catalog == null)
         throw new ArgumentNullException("catalog");
     if ((catalog.CompatibleWith & XCRIProfiles.XCRI_v1_2) == 0)
         return;
     this._WriteStartElement(xmlWriter, "catalog", Configuration.Namespaces.XCRICAP12NamespaceUri);
     if (catalog.Generated.HasValue == false)
         if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP12NamespaceUri)))
             xmlWriter.WriteAttributeString("generated", (new DateTimeOffset(DateTime.Now)).ToISO8601(true));
         else
             xmlWriter.WriteAttributeString("generated", Configuration.Namespaces.XCRICAP12NamespaceUri, (new DateTimeOffset(DateTime.Now)).ToISO8601(true));
     else
         if (String.IsNullOrEmpty(xmlWriter.LookupPrefix(Configuration.Namespaces.XCRICAP12NamespaceUri)))
             xmlWriter.WriteAttributeString("generated", catalog.Generated.Value.ToISO8601(true));
         else
             xmlWriter.WriteAttributeString("generated", Configuration.Namespaces.XCRICAP12NamespaceUri, catalog.Generated.Value.ToISO8601(true));
     this.WriteXCRI12CommonElements(xmlWriter, catalog);
     foreach (XCRI.Interfaces.XCRICAP12.IProvider provider in catalog.Providers)
         if (provider != null)
             this.Write(xmlWriter, provider);
     this._WriteEndElement(xmlWriter);
 }
 protected virtual void _WriteAttribute(
     System.Xml.XmlWriter xmlWriter,
     string attributeName,
     string attributeNamespace,
     string attributeValue,
     string attributeValueNamespace
     )
 {
     if (String.IsNullOrEmpty(attributeValue))
         return;
     if (attributeName.Contains(":"))
     {
         xmlWriter.WriteStartAttribute
             (
             attributeName.Substring(0, attributeName.IndexOf(":")),
             attributeName.Substring(attributeName.IndexOf(":")+1),
             String.Empty
             );
     }
     else
     {
         xmlWriter.WriteStartAttribute
             (
             attributeName,
             attributeNamespace
             );
     }
     if (String.IsNullOrEmpty(attributeValueNamespace))
         xmlWriter.WriteString(attributeValue);
     else
         xmlWriter.WriteString(String.Format
             (
             "{0}:{1}",
             xmlWriter.LookupPrefix(attributeValueNamespace),
             attributeValue
             ));
     xmlWriter.WriteEndAttribute();
 }
Beispiel #6
0
			internal virtual void LookupPrefix(System.Xml.XmlNode node)
			{
				if (node == null)
				{
					throw new ArgumentException("node must not be null");
				}
				string prefix = node.LookupPrefix(@namespace.GetUri());
				if (prefix == null)
				{
					//    check to see if we match the default namespace
					string defaultNamespace = node.LookupNamespaceURI(null);
					if (defaultNamespace == null)
					{
						defaultNamespace = string.Empty;
					}
					string nodeNamespace = @namespace.GetUri();
					if (nodeNamespace.Equals(defaultNamespace))
					{
						prefix = string.Empty;
					}
				}
				int i = 0;
				while (prefix == null)
				{
					string generatedPrefix = "e4x_" + i++;
					string generatedUri = node.LookupNamespaceURI(generatedPrefix);
					if (generatedUri == null)
					{
						prefix = generatedPrefix;
						System.Xml.XmlNode top = node;
						while (top.ParentNode != null && top.ParentNode is XmlElement)
						{
							top = top.ParentNode;
						}
						((XmlElement)top).SetAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, @namespace.GetUri());
					}
				}
				@namespace.SetPrefix(prefix);
			}
Beispiel #7
0
 protected override void WriteBeginElement(System.Xml.XmlWriter writer, object obj, ITypeSerializationInfo info)
 {
     string prefix = info.NamespacePrefix;
     if (prefix == null)
     {
         prefix = writer.LookupPrefix(info.Namespace);
     }
     else if (writer.LookupPrefix(info.Namespace) == null)
     {
         writer.WriteAttributeString("xmlns", prefix, null, info.Namespace);
     }
     string value = prefix + ":" + info.ElementName;
     writer.WriteAttributeString(XMLSchemaInstancePrefix, TypeField, XMLSchemaInstanceNamespace, value);
 }