/// <summary> /// Create a Serializer initialized to write to a given OutputStream. /// Closing the output stream after use is the responsibility of the caller. /// </summary> /// <param name="stream">stream The OutputStream to which the Serializer will write</param> /// <returns> a new Serializer </returns> public Serializer NewSerializer(Stream stream) { Serializer s = new Serializer(); s.SetProcessor(this); s.SetOutputStream(stream); return(s); }
private static SVGImage.SVG.SVGImage _convert(XmlReader xml) { var processor = new Processor(); // Load the source document XdmNode input = processor.NewDocumentBuilder().Build(xml); // Create a transformer for the stylesheet if (transformer == null) { var file = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "libs\\pMML2SVG\\pmml2svg.xsl"); var xslt = XmlReader.Create(file); transformer = processor.NewXsltCompiler().Compile(xslt).Load(); } // Set the root node of the source document to be the initial context node transformer.InitialContextNode = input; var ms = new MemoryStream(); // Create a serializer var serializer = new Serializer(); serializer.SetOutputStream(ms); // Transform the source XML transformer.Run(serializer); serializer.Close(); ms.Position = 0; var img = new SVGImage.SVG.SVGImage(); img.SetImage(ms); return img; }
/** * Runs an XSLT transform, serializing the result to standard output. * * @param name="src" the document to be transformed * @param name="stylesheet" the stylesheet to use */ public static void transform(String src, String stylesheet) { XsltExecutable compiled = compileStylesheet(stylesheet); XsltTransformer transformer = compiled.Load(); XdmNode doc = getSourceRoot(src); if (doc == null) { Console.WriteLine("error: null transform source root node"); Environment.Exit(-1); } transformer.InitialContextNode = doc; Serializer serializer = new Serializer(); serializer.SetOutputStream(Console.OpenStandardOutput()); transformer.Run(serializer); serializer.Close(); }
private void generateButton_Click(object sender, System.EventArgs e) { try { generateButton.Enabled = false; Cursor.Current = Cursors.WaitCursor; Processor processor = new Processor(); DocumentBuilder builder = processor.NewDocumentBuilder(); builder.BaseUri = new Uri(xmlSource.Text); XdmNode input = builder.Build(new FileStream(xmlSource.Text, FileMode.Open)); XsltCompiler compiler = processor.NewXsltCompiler(); compiler.BaseUri = new Uri(htmlDest.Text); XsltTransformer transformer = compiler.Compile(xsltStream).Load(); transformer.InitialContextNode = input; Serializer serializer = new Serializer(); serializer.SetOutputStream(new FileStream(htmlDest.Text, FileMode.Create, FileAccess.Write)); transformer.Run(serializer); Cursor.Current = Cursors.Default; generateButton.Enabled = true; } catch (Exception ex) { Cursor.Current = Cursors.Default; generateButton.Enabled = true; MessageBox.Show(ex.ToString()); } }
/// <summary> /// Show a query producing a document as its result and serializing this to a FileStream /// </summary> public override void run(Uri samplesDir) { Processor processor = new Processor(); XQueryCompiler compiler = processor.NewXQueryCompiler(); compiler.BaseUri = samplesDir.ToString(); compiler.DeclareNamespace("saxon", "http://saxon.sf.net/"); XQueryExecutable exp = compiler.Compile("<saxon:example>{static-base-uri()}</saxon:example>"); XQueryEvaluator eval = exp.Load(); Serializer qout = new Serializer(); qout.SetOutputProperty(Serializer.METHOD, "xml"); qout.SetOutputProperty(Serializer.INDENT, "yes"); qout.SetOutputProperty(Serializer.SAXON_INDENT_SPACES, "1"); qout.SetOutputStream(new FileStream("testoutput.xml", FileMode.Create, FileAccess.Write)); Console.WriteLine("Output written to testoutput.xml"); eval.Run(qout); }
/// <summary> /// Show a query reading an input document using an XmlReader (the .NET XML parser) /// </summary> public override void run(Uri samplesDir) { Processor processor = new Processor(); String inputFileName = new Uri(samplesDir, "data/books.xml").ToString(); XmlTextReader reader = new XmlTextReader(inputFileName, UriConnection.getReadableUriStream(new Uri(samplesDir, "data/books.xml"))); //new FileStream(inputFileName, FileMode.Open, FileAccess.Read)); reader.Normalization = true; // add a validating reader - not to perform validation, but to expand entity references XmlValidatingReader validator = new XmlValidatingReader(reader); validator.ValidationType = ValidationType.None; XdmNode doc = processor.NewDocumentBuilder().Build(validator); XQueryCompiler compiler = processor.NewXQueryCompiler(); XQueryExecutable exp = compiler.Compile("/"); XQueryEvaluator eval = exp.Load(); eval.ContextItem = doc; Serializer qout = new Serializer(); qout.SetOutputProperty(Serializer.METHOD, "xml"); qout.SetOutputProperty(Serializer.INDENT, "yes"); qout.SetOutputStream(new FileStream("testoutput2.xml", FileMode.Create, FileAccess.Write)); eval.Run(qout); }
/// <summary> /// Run the transformation, sending the serialized output to a file /// </summary> public override void run(Uri samplesDir) { // Create a Processor instance. Processor processor = new Processor(); // Load the source document XdmNode input = processor.NewDocumentBuilder().Build(new Uri(samplesDir, "data/books.xml")); // Create a transformer for the stylesheet. XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(samplesDir, "styles/identity.xsl")).Load(); // Set the root node of the source document to be the initial context node transformer.InitialContextNode = input; // Create a serializer String outfile = "OutputFromXsltSimple2.xml"; Serializer serializer = new Serializer(); serializer.SetOutputStream(new FileStream(outfile, FileMode.Create, FileAccess.Write)); // Transform the source XML to System.out. transformer.Run(serializer); Console.WriteLine("\nOutput written to " + outfile + "\n"); }
public IXPathNavigable Process(string uriSource) { //XmlDocument document = new XmlDocument(); //XPathNavigator navigator; //if (validate(uriSource, out navigator)) //{ // // Build the xml file // XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", "UTF-8", String.Empty); // document.AppendChild(declaration); // XmlElement root = document.CreateElement("database"); // XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable); // namespaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // // Add schema information to root. // XmlAttribute schema = document.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); // schema.Value = Path.Combine(path, @"database.xsd"); ; // root.SetAttributeNode(schema); // XmlElement componentTable = document.CreateElement("componentTable"); // root.AppendChild(componentTable); // XmlElement linkTable = document.CreateElement("linkTable"); // root.AppendChild(linkTable); // XmlElement parameterTable = document.CreateElement("parameterTable"); // root.AppendChild(parameterTable); // document.AppendChild(root); String xslt = path + @"\database.xslt"; // Create a Processor instance. Processor processor = new Processor(); // Load the source document XdmNode input = processor.NewDocumentBuilder().Build(new Uri(uriSource)); // Create a transformer for the stylesheet. XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(xslt)).Load(); // Set the root node of the source document to be the initial context node transformer.InitialContextNode = input; // Create a serializer Serializer serializer = new Serializer(); MemoryStream memory = new MemoryStream(); //serializer.SetOutputStream(new FileStream("sample.out", FileMode.Create, FileAccess.Write)); serializer.SetOutputStream(memory); // Transform the source XML to System.out. transformer.Run(serializer); XmlDocument xmlMain = new XmlDocument(); memory.Position = 0; xmlMain.Load(memory); memory.Dispose(); //} return xmlMain; }
/// <summary> /// Demonstrate XQuery Update /// </summary> public override void run(Uri samplesDir) { Processor processor = new Processor(true); DocumentBuilder loader = processor.NewDocumentBuilder(); loader.BaseUri = new Uri(samplesDir, "data/books.xml"); loader.TreeModel = TreeModel.LinkedTree; XdmNode indoc = loader.Build(new Uri(samplesDir, "data/books.xml")); Console.Out.WriteLine("=========== BEFORE UPDATE ==========="); Serializer serializer0 = new Serializer(); serializer0.SetOutputProperty(Serializer.METHOD, "xml"); serializer0.SetOutputProperty(Serializer.INDENT, "yes"); serializer0.SetOutputWriter(Console.Out); processor.WriteXdmValue(indoc, serializer0); String query = "for $i in //PRICE return \n" + "replace value of node $i with $i - 0.05"; XQueryCompiler compiler = processor.NewXQueryCompiler(); compiler.UpdatingEnabled = true; XQueryExecutable exp = compiler.Compile(query); XQueryEvaluator eval = exp.Load(); eval.ContextItem = indoc; XdmNode[] updatedNodes = eval.RunUpdate(); foreach (XdmNode root in updatedNodes) { Uri documentUri = root.DocumentUri; if (documentUri != null && documentUri.Scheme == "file") { Stream stream = UriConnection.getWritableUriStream(documentUri); Serializer serializer = new Serializer(); serializer.SetOutputProperty(Serializer.METHOD, "xml"); serializer.SetOutputProperty(Serializer.INDENT, "yes"); serializer.SetOutputStream(stream); processor.WriteXdmValue(root, serializer); } } Console.Out.WriteLine("=========== AFTER UPDATE ==========="); processor.WriteXdmValue(indoc, serializer0); }