Esempio n. 1
0
		internal static void WriteRelationships (Dictionary <string, PackageRelationship> relationships, Stream stream)
		{
			stream.SetLength(0);

			XmlDocument doc = new XmlDocument ();
			XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
			manager.AddNamespace ("rel", RelationshipNamespace);

			doc.AppendChild (doc.CreateNode (XmlNodeType.XmlDeclaration, "", ""));
			
			XmlNode root = doc.CreateNode (XmlNodeType.Element, "Relationships", RelationshipNamespace);
			doc.AppendChild (root);
			
			foreach (PackageRelationship relationship in relationships.Values)
			{
				XmlNode node = doc.CreateNode (XmlNodeType.Element, "Relationship", RelationshipNamespace);
				
				XmlAttribute idAtt = doc.CreateAttribute ("Id");
				idAtt.Value = relationship.Id;
				node.Attributes.Append(idAtt);
				
				XmlAttribute targetAtt = doc.CreateAttribute ("Target");
				targetAtt.Value = relationship.TargetUri.ToString ();
				node.Attributes.Append(targetAtt);

				if (relationship.TargetMode != TargetMode.Internal) {
					XmlAttribute modeAtt = doc.CreateAttribute ("TargetMode");
					modeAtt.Value = relationship.TargetMode.ToString ();
					node.Attributes.Append (modeAtt);
				}
				XmlAttribute typeAtt = doc.CreateAttribute ("Type");
				typeAtt.Value = relationship.RelationshipType;
				node.Attributes.Append(typeAtt);
				
				root.AppendChild (node);
			}

			using (XmlTextWriter writer = new XmlTextWriter (stream, System.Text.Encoding.UTF8))
				doc.WriteTo (writer);
		}