//------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------
        /// <summary>
        /// Parse the Manifest tag
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="reader">XmlReader positioned to the Manifest tag</param>
        /// <param name="partManifest"></param>
        /// <param name="partEntryManifest"></param>
        /// <param name="relationshipManifest"></param>
        internal static void ParseManifest(
            PackageDigitalSignatureManager manager,
            XmlReader reader,
            out List <Uri> partManifest,
            out List <PartManifestEntry> partEntryManifest,
            out List <PackageRelationshipSelector> relationshipManifest)
        {
            Invariant.Assert(manager != null);
            Invariant.Assert(reader != null);

            // these are empty (non-null) when nothing is found
            partManifest         = new List <Uri>();
            partEntryManifest    = new List <PartManifestEntry>();
            relationshipManifest = new List <PackageRelationshipSelector>();

            // manually parse the Relationship tags because they are custom formed and the Reference class will not handle
            // them correctly
            string referenceTagName = XTable.Get(XTable.ID.ReferenceTagName);
            int    referenceCount   = 0;

            while (reader.Read() && (reader.MoveToContent() == XmlNodeType.Element))
            {
                // should be on a <Reference> tag
                if (String.CompareOrdinal(reader.NamespaceURI, SignedXml.XmlDsigNamespaceUrl) == 0 &&
                    (String.CompareOrdinal(reader.LocalName, referenceTagName) == 0) &&
                    reader.Depth == 2)
                {
                    // Parse each reference - distinguish between Relationships and Parts
                    // because we don't store the Relationship-part itself - just it's Relationships.
                    PartManifestEntry partManifestEntry = ParseReference(reader);
                    if (partManifestEntry.IsRelationshipEntry)
                    {
                        foreach (PackageRelationshipSelector relationshipSelector in partManifestEntry.RelationshipSelectors)
                        {
                            relationshipManifest.Add(relationshipSelector);
                        }
                    }
                    else
                    {
                        partManifest.Add(partManifestEntry.Uri);
                    }

                    // return the manifest entry to be used for hashing
                    partEntryManifest.Add(partManifestEntry);

                    referenceCount++;
                }
                else
                {
                    throw new XmlException(SR.Get(SRID.UnexpectedXmlTag, reader.Name));
                }
            }

            // XmlDSig xsd requires at least one <Reference> tag
            if (referenceCount == 0)
            {
                throw new XmlException(SR.Get(SRID.PackageSignatureCorruption));
            }
        }
        /// <summary>
        /// Assembles the sorted list of relationships for this part entry and
        /// generates a stream with the Xml-equivalent as defined in the Opc spec
        /// </summary>
        /// <param name="partEntry">relationship-type part entry</param>
        /// <returns></returns>
        private Stream GetRelationshipStream(PartManifestEntry partEntry)
        {
            Debug.Assert(partEntry.IsRelationshipEntry);

            //Get the list of relationships from the RelationshipSelectors for this part
            SortedDictionary<String, PackageRelationship> partRelationships = 
                new SortedDictionary<String, PackageRelationship>(StringComparer.Ordinal);
            foreach (PackageRelationshipSelector relationshipSelector in partEntry.RelationshipSelectors)
            {
                foreach (PackageRelationship r in relationshipSelector.Select(_manager.Package))
                {
                    if(!partRelationships.ContainsKey(r.Id))
                        partRelationships.Add(r.Id, r);
                }
            }

            return GenerateRelationshipNodeStream(partRelationships.Values);
        }