Esempio n. 1
0
        /// <summary>
        /// Writes the schema information in an XML format to a byte stream. The stream is closed by this method.
        /// </summary>
        public void SaveAsXml(ISystemContext context, Stream ostrm, bool keepStreamOpen)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Encoding         = Encoding.UTF8;
            settings.CloseOutput      = !keepStreamOpen;
            settings.ConformanceLevel = ConformanceLevel.Document;
            settings.Indent           = true;

            ServiceMessageContext messageContext = new ServiceMessageContext();

            messageContext.NamespaceUris = context.NamespaceUris;
            messageContext.ServerUris    = context.ServerUris;
            messageContext.Factory       = context.EncodeableFactory;

            using (XmlWriter writer = XmlWriter.Create(ostrm, settings)) {
                XmlQualifiedName root    = new XmlQualifiedName("ListOfNodeState", Namespaces.OpcUaXsd);
                XmlEncoder       encoder = new XmlEncoder(root, writer, messageContext);

                encoder.SaveStringTable("NamespaceUris", "NamespaceUri", context.NamespaceUris);
                encoder.SaveStringTable("ServerUris", "ServerUri", context.ServerUris);

                for (int ii = 0; ii < this.Count; ii++)
                {
                    NodeState state = this[ii];

                    if (state != null)
                    {
                        state.SaveAsXml(context, encoder);
                    }
                }

                encoder.Close();
            }
        }