コード例 #1
0
 /// <summary>
 /// Read XML from input source and write XML to output writer,
 /// while transforming text appearing inside the specified XML tags
 /// by applying the specified
 /// <see cref="Java.Util.Function.IFunction{T, R}"><code>Function</code></see>
 /// .
 /// Note that the <code>Function</code> you supply must be
 /// prepared to accept <code>String</code>s as input; if your
 /// <code>Function</code> doesn't handle <code>String</code>s, you
 /// need to write a wrapper for it that does.
 /// <br />
 /// <p><i>Implementation notes:</i> The InputSource is assumed to already
 /// be buffered if useful, and we need a stream, so that the XML decoder
 /// can determine the correct character encoding of the XML file.
 /// TODO: does that mean there's a bug if you send it a Reader
 /// instead of an InputStream?  It seems to work with a Reader...
 /// <br />
 /// The output is to a Writer, and the provided Writer should again
 /// be buffered if desirable.  Internally, this Writer is wrapped as
 /// a PrintWriter.
 /// </summary>
 /// <param name="tags">
 /// an array of <code>String</code>s, each an XML entity
 /// within which the transformation should be applied
 /// </param>
 /// <param name="fn">
 /// the
 /// <see cref="Java.Util.Function.IFunction{T, R}"><code>Function</code></see>
 /// to apply
 /// </param>
 /// <param name="in">the <code>InputStream</code> to read from</param>
 /// <param name="w">the <code>Writer</code> to write to</param>
 /// <param name="saxInterface">the sax handler you would like to use (default is SaxInterface, defined in this class, but you may define your own handler)</param>
 public virtual void TransformXML(string[] tags, IFunction <string, T> fn, InputSource @in, TextWriter w, TransformXML.SAXInterface <T> saxInterface)
 {
     saxInterface.outWriter = new PrintWriter(w, true);
     saxInterface.function  = fn;
     saxInterface.elementsToBeTransformed = new List <string>();
     Sharpen.Collections.AddAll(saxInterface.elementsToBeTransformed, Arrays.AsList(tags));
     try
     {
         saxParser.Parse(@in, saxInterface);
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
コード例 #2
0
 /// <summary>
 /// Calls the fully specified transformXML with an InputSource
 /// constructed from <code>in</code>.
 /// </summary>
 public virtual void TransformXML(string[] tags, IFunction <string, T> fn, Reader @in, TextWriter w, TransformXML.SAXInterface <T> handler)
 {
     TransformXML(tags, fn, new InputSource(@in), w, handler);
 }