Ejemplo n.º 1
0
        public string serialize(XPathNodeIterator arg, XPathNodeIterator parameters)
        {
            // fn:serialize($arg	as item()*, $params as element(output:serialization-parameters)?) as xs:string

            var itemFactory = new SystemItemFactory();

            XPathSerializationOptions options = null;

            if (parameters != null &&
                parameters.Count == 1)
            {
                options = new XPathSerializationOptions();
                ((IXmlSerializable)options).ReadXml(parameters.Cast <XPathNavigator>().First().ReadSubtree());
            }

            using (var writer = new StringWriter()) {
                IEnumerable <XPathItem> items = arg.Cast <XPathItem>();

                if (options == null)
                {
                    itemFactory.Serialize(items, writer);
                }
                else
                {
                    itemFactory.Serialize(items, writer, options);
                }

                return(writer.ToString());
            }
        }
Ejemplo n.º 2
0
        public virtual void Validate(TextWriter output, SchematronRuntimeOptions options)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            XmlWriter writer;
            XPathSerializationOptions serialization = options.Serialization;

            if (serialization != null)
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                serialization.CopyTo(settings);

                writer = XmlWriter.Create(output, settings);
            }
            else
            {
                writer = XmlWriter.Create(output);
            }

            Validate(writer, options);

            writer.Close();
        }
Ejemplo n.º 3
0
        public void To(XmlWriter output, XPathSerializationOptions options)
        {
            OverrideSerialization(options);

            this.validator.Validate(output, this.options);

            RestoreSerialization(options);
        }
Ejemplo n.º 4
0
        public void To(XmlWriter output, XPathSerializationOptions options)
        {
            OverrideSerialization(options);

            this.executable.Run(output, this.options);

            RestoreSerialization(options);
        }
Ejemplo n.º 5
0
        void RestoreSerialization(XPathSerializationOptions options)
        {
            if (options == null)
            {
                return;
            }

            this.options.Serialization = this.defaultSerialization;
        }
Ejemplo n.º 6
0
        void OverrideSerialization(XPathSerializationOptions options)
        {
            if (options == null)
            {
                return;
            }

            this.options.Serialization = options;
        }
Ejemplo n.º 7
0
        public override void Serialize(IEnumerable <XPathItem> items, Stream output, XPathSerializationOptions options)
        {
            options = options ?? new XPathSerializationOptions();

            Serializer serializer = CreateSerializer(options);

            serializer.SetOutputStream(output);

            Serialize(items, serializer);
        }
Ejemplo n.º 8
0
        public Serializer CreateSerializer(XPathSerializationOptions options)
        {
            var serializer = new Serializer();

            if (options.ByteOrderMark.HasValue)
            {
                serializer.SetOutputProperty(Serializer.BYTE_ORDER_MARK, (options.ByteOrderMark.Value) ? "yes" : "no");
            }

            if (options.ConformanceLevel == ConformanceLevel.Document)
            {
                serializer.SetOutputProperty(Serializer.SAXON_REQUIRE_WELL_FORMED, "yes");
            }

            if (options.DocTypePublic != null)
            {
                serializer.SetOutputProperty(Serializer.DOCTYPE_PUBLIC, options.DocTypePublic);
            }

            if (options.DocTypeSystem != null)
            {
                serializer.SetOutputProperty(Serializer.DOCTYPE_SYSTEM, options.DocTypeSystem);
            }

            if (options.Encoding != null)
            {
                serializer.SetOutputProperty(Serializer.ENCODING, options.Encoding.WebName);
            }

            if (options.Indent.HasValue)
            {
                serializer.SetOutputProperty(Serializer.INDENT, (options.Indent.Value) ? "yes" : "no");
            }

            if (options.MediaType != null)
            {
                serializer.SetOutputProperty(Serializer.MEDIA_TYPE, options.MediaType);
            }

            if (options.Method != null &&
                options.Method.Namespace.Length == 0)
            {
                serializer.SetOutputProperty(Serializer.METHOD, options.Method.Name);
            }

            if (options.OmitXmlDeclaration.HasValue)
            {
                serializer.SetOutputProperty(Serializer.OMIT_XML_DECLARATION, (options.OmitXmlDeclaration.Value) ? "yes" : "no");
            }

            return(serializer);
        }
Ejemplo n.º 9
0
        public void Serialize(TextWriter output, XPathItemFactory itemFactory)
        {
            if (this.Content == null)
            {
                return;
            }

            var serialization = new XPathSerializationOptions {
                Method = this.Method,
            };

            itemFactory.Serialize(this.Content, output, serialization);
        }
Ejemplo n.º 10
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                XdmNode node = arguments[0].AsNodes().Single();

                var options = new XPathSerializationOptions();

                XdmItem arg2 = null;

                if (arguments.Length > 1 &&
                    (arg2 = arguments[1].AsItems().SingleOrDefault()) != null)
                {
                    if (arg2.IsAtomic())
                    {
                        string methodLexical = arg2.ToString();

                        QName method = (context.ContextItem == null || context.ContextItem.IsAtomic()) ?
                                       new QName(methodLexical)
                     : new QName(methodLexical, (XdmNode)context.ContextItem);

                        options.Method = method.ToXmlQualifiedName();
                    }
                }

                Serializer serializer = this.itemFactory.CreateSerializer(options);

                if (arg2 != null &&
                    !arg2.IsAtomic())
                {
                    foreach (XdmNode attr in ((IXdmEnumerator)((XdmNode)arg2).EnumerateAxis(XdmAxis.Attribute)).AsNodes())
                    {
                        serializer.SetOutputProperty(attr.NodeName, attr.StringValue);
                    }
                }

                using (var writer = new StringWriter()) {
                    serializer.SetOutputWriter(writer);

                    this.itemFactory.processor.WriteXdmValue(node, serializer);

                    return(writer.ToString().ToXdmAtomicValue().GetXdmEnumerator());
                }
            }
Ejemplo n.º 11
0
        public void Serialize(Stream output, XPathItemFactory itemFactory, XmlQualifiedName method)
        {
            if (this.Content == null)
            {
                throw new InvalidOperationException("Content cannot be null.");
            }

            XPathItem item = this.Content;

            if (method == ExtensionMethods.Base64Binary)
            {
                byte[] buffer = (!item.IsNode && item.XmlType.TypeCode == XmlTypeCode.Base64Binary) ?
                                (byte[])item.TypedValue
               : Convert.FromBase64String(item.Value);

                output.Write(buffer, 0, buffer.Length);
            }
            else if (method == ExtensionMethods.HexBinary)
            {
                byte[] buffer = (!item.IsNode && item.XmlType.TypeCode == XmlTypeCode.HexBinary) ?
                                (byte[])item.TypedValue :
                                fromBinHexString(item.Value);

                output.Write(buffer, 0, buffer.Length);
            }
            else
            {
                var serialization = new XPathSerializationOptions {
                    Indent             = this.Indent,
                    OmitXmlDeclaration = this.OmitXmlDeclaration,
                    MediaType          = this.MediaType,
                    Method             = method,
                    DocTypePublic      = this.DocTypePublic,
                    DocTypeSystem      = this.DocTypeSystem,
                    Encoding           = this.Encoding,
                    ByteOrderMark      = this.ByteOrderMark
                };

                itemFactory.Serialize(item, output, serialization);
            }
        }
Ejemplo n.º 12
0
 internal SchematronResultHandler(SchematronValidator validator, SchematronRuntimeOptions options)
 {
     this.validator            = validator;
     this.options              = options;
     this.defaultSerialization = options.Serialization;
 }
Ejemplo n.º 13
0
 internal XQueryResultHandler(XQueryExecutable executable, XQueryRuntimeOptions options)
 {
     this.executable           = executable;
     this.options              = options;
     this.defaultSerialization = options.Serialization;
 }