public void To(TextWriter output, XPathSerializationOptions options)
        {
            OverrideSerialization(options);

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

             RestoreSerialization(options);
        }
Exemple #2
0
        public virtual void Serialize(IEnumerable <XPathItem> items, Stream output, XPathSerializationOptions options)
        {
            options = options ?? new XPathSerializationOptions();

            XmlWriter writer = XmlWriter.Create(output, (XmlWriterSettings)options);

            if (options.Method == XPathSerializationMethods.XHtml)
            {
                writer = new XHtmlWriter(writer);
            }

            Serialize(items, writer);

            // NOTE: don't close writer if Serialize fails
            writer.Close();
        }
        static void CopyTo(XPathSerializationOptions options, XmlWriterSettings settings)
        {
            if (options == null) throw new ArgumentNullException("options");
             if (settings == null) throw new ArgumentNullException("settings");

             if (options.Method != null
            && !options.Method.IsEmpty
            && options.Method != XPathSerializationMethods.Xml) {

            if (options.Method == XPathSerializationMethods.Html) {
               setOutputMethod(settings, XmlOutputMethod.Html);

            } else if (options.Method == XPathSerializationMethods.Text) {
               setOutputMethod(settings, XmlOutputMethod.Text);
            }
             }

             if (options.DocTypePublic != null) {
            setDocTypePublic(settings, options.DocTypePublic);
             }

             if (options.DocTypeSystem != null) {
            setDocTypeSystem(settings, options.DocTypeSystem);
             }

             if (options.Encoding != null) {
            settings.Encoding = options.Encoding;
             }

             if (options.Indent.HasValue) {
            settings.Indent = options.Indent.Value;
             }

             if (options.MediaType != null) {
            setMediaType(settings, options.MediaType);
             }

             if (options.OmitXmlDeclaration.HasValue) {
            settings.OmitXmlDeclaration = options.OmitXmlDeclaration.Value;
             }

             Encoding enc = settings.Encoding;

             if (options.ByteOrderMark.HasValue
            && !options.ByteOrderMark.Value) {

            if (enc is UTF8Encoding) {
               settings.Encoding = new UTF8Encoding(false);
            }
             }

             settings.ConformanceLevel = options.ConformanceLevel;
        }
 internal SchematronResultHandler(SchematronValidator validator, SchematronRuntimeOptions options)
 {
     this.validator = validator;
      this.options = options;
      this.defaultSerialization = options.Serialization;
 }
        void RestoreSerialization(XPathSerializationOptions options)
        {
            if (options == null) {
            return;
             }

             this.options.Serialization = this.defaultSerialization;
        }
        void OverrideSerialization(XPathSerializationOptions options)
        {
            if (options == null) {
            return;
             }

             this.options.Serialization = options;
        }
Exemple #7
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);
             }
        }
Exemple #8
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();
                }
            }
        static void CopyTo(XPathSerializationOptions options, XmlWriterSettings settings)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (options.Method != null &&
                !options.Method.IsEmpty &&
                options.Method != XPathSerializationMethods.Xml)
            {
                if (options.Method == XPathSerializationMethods.Html)
                {
                    setOutputMethod(settings, XmlOutputMethod.Html);
                }
                else if (options.Method == XPathSerializationMethods.Text)
                {
                    setOutputMethod(settings, XmlOutputMethod.Text);
                }
            }

            if (options.DocTypePublic != null)
            {
                setDocTypePublic(settings, options.DocTypePublic);
            }

            if (options.DocTypeSystem != null)
            {
                setDocTypeSystem(settings, options.DocTypeSystem);
            }

            if (options.Encoding != null)
            {
                settings.Encoding = options.Encoding;
            }

            if (options.Indent.HasValue)
            {
                settings.Indent = options.Indent.Value;
            }

            if (options.MediaType != null)
            {
                setMediaType(settings, options.MediaType);
            }

            if (options.OmitXmlDeclaration.HasValue)
            {
                settings.OmitXmlDeclaration = options.OmitXmlDeclaration.Value;
            }

            Encoding enc = settings.Encoding;

            if (options.ByteOrderMark.HasValue &&
                !options.ByteOrderMark.Value)
            {
                if (enc is UTF8Encoding)
                {
                    settings.Encoding = new UTF8Encoding(false);
                }
            }

            settings.ConformanceLevel = options.ConformanceLevel;
        }
Exemple #10
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();
             }
        }
Exemple #11
0
        public virtual void Serialize(IEnumerable<XPathItem> items, TextWriter output, XPathSerializationOptions options)
        {
            options = options ?? new XPathSerializationOptions();

             XmlWriter writer = XmlWriter.Create(output, (XmlWriterSettings)options);

             if (options.Method == XPathSerializationMethods.XHtml) {
            writer = new XHtmlWriter(writer);
             }

             Serialize(items, writer);

             // NOTE: don't close writer if Serialize fails
             writer.Close();
        }
Exemple #12
0
 public void Serialize(XPathItem item, TextWriter output, XPathSerializationOptions options)
 {
     Serialize(new XPathItem[1] { item }, output, options);
 }
Exemple #13
0
 public void Serialize(XPathItem item, TextWriter output, XPathSerializationOptions options)
 {
     Serialize(new XPathItem[1] {
         item
     }, output, options);
 }
Exemple #14
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);
        }