// // Private methods // void Initialize() { encoding = Encoding.UTF8; omitXmlDecl = false; newLineHandling = NewLineHandling.Replace; newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix indent = TriState.Unknown; indentChars = " "; newLineOnAttributes = false; closeOutput = false; namespaceHandling = NamespaceHandling.Default; conformanceLevel = ConformanceLevel.Document; checkCharacters = true; writeEndDocumentOnClose = true; #if !SILVERLIGHT outputMethod = XmlOutputMethod.Xml; cdataSections.Clear(); mergeCDataSections = false; mediaType = null; docTypeSystem = null; docTypePublic = null; standalone = XmlStandalone.Omit; doNotEscapeUriAttributes = false; #endif #if ASYNC || FEATURE_NETCORE useAsync = false; #endif isReadOnly = false; }
/// <summary> /// If a wrapped writer has not yet been created, create one. /// </summary> private void EnsureWrappedWriter(XmlOutputMethod outMethod) { if (_wrapped == null) { CreateWrappedWriter(outMethod); } }
/// <summary> /// Create either the Html or Xml writer and send any cached events to it. /// </summary> private void CreateWrappedWriter(XmlOutputMethod outMethod) { Debug.Assert(_wrapped == null); // Create either the Xml or Html writer _writerSettings.ReadOnly = false; _writerSettings.OutputMethod = outMethod; // If Indent was not set by the user, then default to True for Html if (outMethod == XmlOutputMethod.Html && _writerSettings.IndentInternal == TriState.Unknown) { _writerSettings.Indent = true; } _writerSettings.ReadOnly = true; if (_textWriter != null) { _wrapped = ((XmlWellFormedWriter)XmlWriter.Create(_textWriter, _writerSettings)).RawWriter; } else { _wrapped = ((XmlWellFormedWriter)XmlWriter.Create(_strm, _writerSettings)).RawWriter; } // Send cached events to the new writer _eventCache.EndEvents(); _eventCache.EventsToWriter(_wrapped); // Send OnRemoveWriter event if (_onRemove != null) { (this._onRemove)(_wrapped); } }
private void EnsureWrappedWriter(XmlOutputMethod outMethod) { if (this.wrapped == null) { this.CreateWrappedWriter(outMethod); } }
internal XmlWriterSettings(XmlQueryDataReader reader) { this.cdataSections = new List <XmlQualifiedName>(); this.Encoding = System.Text.Encoding.GetEncoding(reader.ReadInt32()); this.OmitXmlDeclaration = reader.ReadBoolean(); this.NewLineHandling = (System.Xml.NewLineHandling)reader.ReadSByte(0, 2); this.NewLineChars = reader.ReadStringQ(); this.IndentInternal = (TriState)reader.ReadSByte(-1, 1); this.IndentChars = reader.ReadStringQ(); this.NewLineOnAttributes = reader.ReadBoolean(); this.CloseOutput = reader.ReadBoolean(); this.ConformanceLevel = (System.Xml.ConformanceLevel)reader.ReadSByte(0, 2); this.CheckCharacters = reader.ReadBoolean(); this.outputMethod = (XmlOutputMethod)reader.ReadSByte(0, 3); int capacity = reader.ReadInt32(); this.cdataSections = new List <XmlQualifiedName>(capacity); for (int i = 0; i < capacity; i++) { this.cdataSections.Add(new XmlQualifiedName(reader.ReadString(), reader.ReadString())); } this.mergeCDataSections = reader.ReadBoolean(); this.mediaType = reader.ReadStringQ(); this.docTypeSystem = reader.ReadStringQ(); this.docTypePublic = reader.ReadStringQ(); this.Standalone = (XmlStandalone)reader.ReadSByte(0, 2); this.autoXmlDecl = reader.ReadBoolean(); this.ReadOnly = reader.ReadBoolean(); }
// // Private methods // private void Initialize() { _encoding = Encoding.UTF8; _omitXmlDecl = false; _newLineHandling = NewLineHandling.Replace; _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix _indent = TriState.Unknown; _indentChars = " "; _newLineOnAttributes = false; _closeOutput = false; _namespaceHandling = NamespaceHandling.Default; _conformanceLevel = ConformanceLevel.Document; _checkCharacters = true; _writeEndDocumentOnClose = true; _outputMethod = XmlOutputMethod.Xml; _cdataSections.Clear(); _mergeCDataSections = false; _mediaType = null; _docTypeSystem = null; _docTypePublic = null; _standalone = XmlStandalone.Omit; _doNotEscapeUriAttributes = false; _useAsync = false; _isReadOnly = false; }
/// <summary>Resets the members of the settings class to their default values.</summary> public void Reset() { this.checkCharacters = true; this.closeOutput = false; this.conformance = ConformanceLevel.Document; this.encoding = Encoding.UTF8; this.indent = false; this.indentChars = " "; this.newLineChars = Environment.NewLine; this.newLineOnAttributes = false; this.newLineHandling = NewLineHandling.None; this.omitXmlDeclaration = false; this.outputMethod = XmlOutputMethod.AutoDetect; }
public static string Translate(XmlOutputMethod type) { switch (type) { case XmlOutputMethod.Text: return(TEXT); case XmlOutputMethod.Xml: return(XML); case XmlOutputMethod.Html: return(HTML); } return(null); }
public void Reset() { checkCharacters = true; closeOutput = false; // ? not documented conformance = ConformanceLevel.Document; encoding = Encoding.UTF8; indent = false; indentChars = " "; newLineChars = "\r\n"; newLineOnAttributes = false; newLineHandling = NewLineHandling.Replace; omitXmlDeclaration = false; outputMethod = XmlOutputMethod.AutoDetect; isAsync = false; }
public void Reset() { checkCharacters = true; closeOutput = false; conformance = ConformanceLevel.Document; encoding = Encoding.UTF8; indent = false; indentChars = " "; newLineChars = Environment.NewLine; newLineOnAttributes = false; newLineHandling = NewLineHandling.Replace; normalizeNewLines = true; omitXmlDeclaration = false; outputMethod = XmlOutputMethod.AutoDetect; }
public void Reset() { checkCharacters = true; closeOutput = false; // ? not documented conformance = ConformanceLevel.Document; encoding = Encoding.UTF8; indent = false; indentChars = " "; // LAMESPEC: MS.NET says it is "\r\n", but it is silly decision. newLineChars = Environment.NewLine; newLineOnAttributes = false; newLineHandling = NewLineHandling.None; omitXmlDeclaration = false; outputMethod = XmlOutputMethod.AutoDetect; }
public void Reset () { checkCharacters = true; closeOutput = false; // ? not documented conformance = ConformanceLevel.Document; encoding = Encoding.UTF8; indent = false; indentChars = " "; // LAMESPEC: MS.NET says it is "\r\n", but it is silly decision. newLineChars = Environment.NewLine; newLineOnAttributes = false; newLineHandling = NewLineHandling.None; omitXmlDeclaration = false; outputMethod = XmlOutputMethod.AutoDetect; }
private XmlWriterSettings(XmlWriterSettings org) { checkCharacters = org.checkCharacters; closeOutput = org.closeOutput; conformance = org.conformance; encoding = org.encoding; indent = org.indent; indentChars = org.indentChars; newLineChars = org.newLineChars; newLineOnAttributes = org.newLineOnAttributes; newLineHandling = org.newLineHandling; normalizeNewLines = org.normalizeNewLines; outputMethod = org.outputMethod; omitXmlDeclaration = org.omitXmlDeclaration; }
/// <summary> /// Deserialize the object from BinaryReader. /// </summary> internal XmlWriterSettings(XmlQueryDataReader reader) { // Encoding encoding; Encoding = Encoding.GetEncoding(reader.ReadInt32()); // bool omitXmlDecl; OmitXmlDeclaration = reader.ReadBoolean(); // NewLineHandling newLineHandling; NewLineHandling = (NewLineHandling)reader.ReadSByte(0, (sbyte)NewLineHandling.None); // string newLineChars; NewLineChars = reader.ReadStringQ(); // TriState indent; IndentInternal = (TriState)reader.ReadSByte((sbyte)TriState.Unknown, (sbyte)TriState.True); // string indentChars; IndentChars = reader.ReadStringQ(); // bool newLineOnAttributes; NewLineOnAttributes = reader.ReadBoolean(); // bool closeOutput; CloseOutput = reader.ReadBoolean(); // ConformanceLevel conformanceLevel; ConformanceLevel = (ConformanceLevel)reader.ReadSByte(0, (sbyte)ConformanceLevel.Document); // bool checkCharacters; CheckCharacters = reader.ReadBoolean(); // XmlOutputMethod outputMethod; _outputMethod = (XmlOutputMethod)reader.ReadSByte(0, (sbyte)XmlOutputMethod.AutoDetect); // List<XmlQualifiedName> cdataSections; int length = reader.ReadInt32(); _cdataSections = new List <XmlQualifiedName>(length); for (int idx = 0; idx < length; idx++) { _cdataSections.Add(new XmlQualifiedName(reader.ReadString(), reader.ReadString())); } // bool mergeCDataSections; _mergeCDataSections = reader.ReadBoolean(); // string mediaType; _mediaType = reader.ReadStringQ(); // string docTypeSystem; _docTypeSystem = reader.ReadStringQ(); // string docTypePublic; _docTypePublic = reader.ReadStringQ(); // XmlStandalone standalone; Standalone = (XmlStandalone)reader.ReadSByte(0, (sbyte)XmlStandalone.No); // bool autoXmlDecl; _autoXmlDecl = reader.ReadBoolean(); // bool isReadOnly; ReadOnly = reader.ReadBoolean(); }
protected XmlEncodedRawTextWriter(XmlWriterSettings settings) { this.xmlCharType = XmlCharType.Instance; this.bufPos = 1; this.textPos = 1; this.bufLen = 0x1800; this.newLineHandling = settings.NewLineHandling; this.omitXmlDeclaration = settings.OmitXmlDeclaration; this.newLineChars = settings.NewLineChars; this.checkCharacters = settings.CheckCharacters; this.closeOutput = settings.CloseOutput; this.standalone = settings.Standalone; this.outputMethod = settings.OutputMethod; this.mergeCDataSections = settings.MergeCDataSections; if (this.checkCharacters && (this.newLineHandling == NewLineHandling.Replace)) { this.ValidateContentChars(this.newLineChars, "NewLineChars", false); } }
protected XmlUtf8RawTextWriter(XmlWriterSettings settings) { this.xmlCharType = XmlCharType.Instance; this.bufPos = 1; this.textPos = 1; this.bufLen = 0x1800; this.newLineHandling = settings.NewLineHandling; this.omitXmlDeclaration = settings.OmitXmlDeclaration; this.newLineChars = settings.NewLineChars; this.checkCharacters = settings.CheckCharacters; this.closeOutput = settings.CloseOutput; this.standalone = settings.Standalone; this.outputMethod = settings.OutputMethod; this.mergeCDataSections = settings.MergeCDataSections; if (this.checkCharacters && (this.newLineHandling == NewLineHandling.Replace)) { this.ValidateContentChars(this.newLineChars, "NewLineChars", false); } }
private void Initialize() { this.encoding = System.Text.Encoding.UTF8; this.omitXmlDecl = false; this.newLineHandling = System.Xml.NewLineHandling.Replace; this.newLineChars = Environment.NewLine; this.indent = TriState.Unknown; this.indentChars = " "; this.newLineOnAttributes = false; this.closeOutput = false; this.namespaceHandling = System.Xml.NamespaceHandling.Default; this.conformanceLevel = System.Xml.ConformanceLevel.Document; this.checkCharacters = true; this.outputMethod = XmlOutputMethod.Xml; this.cdataSections.Clear(); this.mergeCDataSections = false; this.mediaType = null; this.docTypeSystem = null; this.docTypePublic = null; this.standalone = XmlStandalone.Omit; this.isReadOnly = false; }
private void CreateWrappedWriter(XmlOutputMethod outMethod) { this.writerSettings.ReadOnly = false; this.writerSettings.OutputMethod = outMethod; if ((outMethod == XmlOutputMethod.Html) && (this.writerSettings.IndentInternal == TriState.Unknown)) { this.writerSettings.Indent = true; } this.writerSettings.ReadOnly = true; if (this.textWriter != null) { this.wrapped = ((XmlWellFormedWriter) XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter; } else { this.wrapped = ((XmlWellFormedWriter) XmlWriter.Create(this.strm, this.writerSettings)).RawWriter; } this.eventCache.EndEvents(); this.eventCache.EventsToWriter(this.wrapped); if (this.onRemove != null) { this.onRemove(this.wrapped); } }
// // Public methods // public void Reset() { encoding = Encoding.UTF8; omitXmlDecl = false; newLineHandling = NewLineHandling.Replace; newLineChars = "\r\n"; indent = TriState.Unknown; indentChars = " "; newLineOnAttributes = false; closeOutput = false; conformanceLevel = ConformanceLevel.Document; checkCharacters = true; outputMethod = XmlOutputMethod.Xml; cdataSections = null; mergeCDataSections = false; mediaType = null; docTypeSystem = null; docTypePublic = null; standalone = XmlStandalone.Omit; isReadOnly = false; }
private void CreateWrappedWriter(XmlOutputMethod outMethod) { this.writerSettings.ReadOnly = false; this.writerSettings.OutputMethod = outMethod; if ((outMethod == XmlOutputMethod.Html) && (this.writerSettings.IndentInternal == TriState.Unknown)) { this.writerSettings.Indent = true; } this.writerSettings.ReadOnly = true; if (this.textWriter != null) { this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter; } else { this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.strm, this.writerSettings)).RawWriter; } this.eventCache.EndEvents(); this.eventCache.EventsToWriter(this.wrapped); if (this.onRemove != null) { this.onRemove(this.wrapped); } }
/// <summary> /// If a wrapped writer has not yet been created, create one. /// </summary> private void EnsureWrappedWriter(XmlOutputMethod outMethod) { if (_wrapped == null) CreateWrappedWriter(outMethod); }
public void Reset () { checkCharacters = true; closeOutput = false; // ? not documented conformance = ConformanceLevel.Document; encoding = Encoding.UTF8; indent = false; indentChars = " "; newLineChars = "\r\n"; newLineOnAttributes = false; newLineHandling = NewLineHandling.Replace; omitXmlDeclaration = false; outputMethod = XmlOutputMethod.AutoDetect; #if NET_4_5 isAsync = false; #endif }
// // Constructors // // Construct and initialize an instance of this class. protected XmlEncodedRawTextWriter( XmlWriterSettings settings ) { #if ASYNC useAsync = settings.Async; #endif // copy settings newLineHandling = settings.NewLineHandling; omitXmlDeclaration = settings.OmitXmlDeclaration; newLineChars = settings.NewLineChars; checkCharacters = settings.CheckCharacters; closeOutput = settings.CloseOutput; standalone = settings.Standalone; outputMethod = settings.OutputMethod; mergeCDataSections = settings.MergeCDataSections; if ( checkCharacters && newLineHandling == NewLineHandling.Replace ) { ValidateContentChars( newLineChars, "NewLineChars", false ); } }
// Does not suppress errors. In case of error, null is returned. private XmlQualifiedName ParseOutputMethod(string attValue, out XmlOutputMethod method) { string prefix, localName, namespaceName; ResolveQName(/*ignoreDefaultNs:*/true, attValue, out localName, out namespaceName, out prefix); method = XmlOutputMethod.AutoDetect; if (_compiler.IsPhantomNamespace(namespaceName)) { return null; } else if (prefix.Length == 0) { switch (localName) { case "xml": method = XmlOutputMethod.Xml; break; case "html": method = XmlOutputMethod.Html; break; case "text": method = XmlOutputMethod.Text; break; default: ReportError(/*[XT1570]*/SR.Xslt_InvalidAttrValue, nameof(method), attValue); return null; } } else { if (!_input.ForwardCompatibility) { ReportWarning(/*[XT1570]*/SR.Xslt_InvalidMethod, attValue); } } return new XmlQualifiedName(localName, namespaceName); }
/// <summary> /// Performs xsl transformation after static Data. /// </summary> /// <returns>awaitable Task with output file name proposal for transformation result or null if errors occured</returns> public async Task <string> Transform() { // Check xml input file ObservableCollection <XmlStylesheet> checkReturn = await CheckXmlFile(Data.XmlInputPath); // return if errors occured if (checkReturn == null) { return(null); } // Create the XmlReader instance for input file XmlReader inputReader = XmlReader.Create(Data.XmlInputPath, mXmlReaderSettings); // Create argument list for XSLT parameters XsltArgumentList arguments = new XsltArgumentList(); // initialize XslCompiledTransform instance XslCompiledTransform xslt = null; // Recreate memory stream for transformation output OutputStream?.Close(); OutputStream = new MemoryStream(); // Create memory stream for transformation input MemoryStream inputStream = new MemoryStream(); // Initialize path variable to remember last processed stylesheet string lastProcessedStylesheet = String.Empty; // iterate over stylesheet list bool stylesheetOkay; bool first = true; foreach (XsltStylesheet stylesheet in Data.Stylesheets) { // Check xslt file stylesheetOkay = await CheckStylesheet(stylesheet.Path); if (!stylesheetOkay) { inputStream.Close(); OutputStream.Close(); return(null); } // Create new XslCompiledTransform instance and load the stylesheet xslt = new XslCompiledTransform(); xslt.Load(stylesheet.Path, mXsltSettings, mXmlUrlResolver); // empty out xslt arguments arguments.Clear(); // iterate over parameter list foreach (StylesheetParameter parameter in stylesheet.Parameters) { // add parameter to argument list arguments.AddParam(parameter.Name, String.Empty, parameter.Value); } // input stream is used if there are more than one stylesheet in the list if (!first) { // dispose and recreate input stream inputStream.Close(); inputStream = new MemoryStream(); // copy output stream to input stream OutputStream.WriteTo(inputStream); // dispose and recreate output stream OutputStream.Close(); OutputStream = new MemoryStream(); // reset input stream position to read from the beginning inputStream.Seek(0, SeekOrigin.Begin); // recreate input reader from input stream with settings inputReader = XmlReader.Create(inputStream, mXmlReaderSettings); // try to parse the xml in stream to test it try { while (inputReader.Read()) { ; } } catch (Exception e) { PrepareMessage(MessageType.XslTransformationResultError, new object[] { lastProcessedStylesheet, e.Message }); await MessageAsync(); inputStream.Close(); OutputStream.Close(); return(null); } // reset input stream position to read from the beginning inputStream.Seek(0, SeekOrigin.Begin); // recreate input reader to read from the beginning inputReader = XmlReader.Create(inputStream, mXmlReaderSettings); } // Try to apply the transformation, put result to output stream try { xslt.Transform(inputReader, arguments, OutputStream); } catch (Exception e) { PrepareMessage(MessageType.XslTransformationError, new object[] { stylesheet.Path, e.Message }); await MessageAsync(); inputStream.Close(); OutputStream.Close(); return(null); } // remember last processed stylesheets for possible error messages lastProcessedStylesheet = stylesheet.Path; // reset output stream position to read from the beginning OutputStream.Seek(0, SeekOrigin.Begin); if (first) { first = false; } } // close input stream as it is no longer needed inputStream.Close(); // Store output encoding OutputEncoding = xslt.OutputSettings.Encoding; // Propose input directory as output directory string outputDirectoryProposal = Path.GetDirectoryName(Data.XmlInputPath); // Get xml input file name without extension string inputFileNameWithoutExtension = Path.GetFileNameWithoutExtension(Data.XmlInputPath); // Get output method (Xml | Html | Text) XmlOutputMethod outputMethod = xslt.OutputSettings.OutputMethod; // Make extension proposal dependant from output method string extensionProposal = String.Empty; switch (outputMethod) { case XmlOutputMethod.Html: extensionProposal = "html"; break; case XmlOutputMethod.Text: extensionProposal = "txt"; break; default: extensionProposal = "xml"; break; } // return concatenated output file name proposal return(inputFileNameWithoutExtension + ".out." + extensionProposal); }
/// <summary> /// Deserialize the object from BinaryReader. /// </summary> internal XmlWriterSettings(XmlQueryDataReader reader) { // Encoding encoding; Encoding = Encoding.GetEncoding(reader.ReadInt32()); // bool omitXmlDecl; OmitXmlDeclaration = reader.ReadBoolean(); // NewLineHandling newLineHandling; NewLineHandling = (NewLineHandling)reader.ReadSByte(0, (sbyte)NewLineHandling.None); // string newLineChars; NewLineChars = reader.ReadStringQ(); // TriState indent; IndentInternal = (TriState)reader.ReadSByte((sbyte)TriState.Unknown, (sbyte)TriState.True); // string indentChars; IndentChars = reader.ReadStringQ(); // bool newLineOnAttributes; NewLineOnAttributes = reader.ReadBoolean(); // bool closeOutput; CloseOutput = reader.ReadBoolean(); // ConformanceLevel conformanceLevel; ConformanceLevel = (ConformanceLevel)reader.ReadSByte(0, (sbyte)ConformanceLevel.Document); // bool checkCharacters; CheckCharacters = reader.ReadBoolean(); // XmlOutputMethod outputMethod; outputMethod = (XmlOutputMethod)reader.ReadSByte(0, (sbyte)XmlOutputMethod.AutoDetect); // List<XmlQualifiedName> cdataSections; int length = reader.ReadInt32(); cdataSections = new List<XmlQualifiedName>(length); for (int idx = 0; idx < length; idx++) { cdataSections.Add(new XmlQualifiedName(reader.ReadString(), reader.ReadString())); } // bool mergeCDataSections; mergeCDataSections = reader.ReadBoolean(); // string mediaType; mediaType = reader.ReadStringQ(); // string docTypeSystem; docTypeSystem = reader.ReadStringQ(); // string docTypePublic; docTypePublic = reader.ReadStringQ(); // XmlStandalone standalone; Standalone = (XmlStandalone)reader.ReadSByte(0, (sbyte)XmlStandalone.No); // bool autoXmlDecl; autoXmlDecl = reader.ReadBoolean(); // bool isReadOnly; ReadOnly = reader.ReadBoolean(); }
/// <summary> /// Create either the Html or Xml writer and send any cached events to it. /// </summary> private void CreateWrappedWriter(XmlOutputMethod outMethod) { Debug.Assert(this.wrapped == null); // Create either the Xml or Html writer this.writerSettings.ReadOnly = false; this.writerSettings.OutputMethod = outMethod; // If Indent was not set by the user, then default to True for Html if (outMethod == XmlOutputMethod.Html && this.writerSettings.IndentInternal == TriState.Unknown) this.writerSettings.Indent = true; this.writerSettings.ReadOnly = true; if (textWriter != null) this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter; else this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.strm, this.writerSettings)).RawWriter; // Send cached events to the new writer this.eventCache.EndEvents(); this.eventCache.EventsToWriter(this.wrapped); // Send OnRemoveWriter event if (this.onRemove != null) (this.onRemove)(this.wrapped); }
// // Constructors // // Construct and initialize an instance of this class. protected XmlUtf8RawTextWriter( XmlWriterSettings settings, bool closeOutput ) { // copy settings newLineHandling = settings.NewLineHandling; omitXmlDeclaration = settings.OmitXmlDeclaration; newLineChars = settings.NewLineChars; standalone = settings.Standalone; outputMethod = settings.OutputMethod; checkCharacters = settings.CheckCharacters; mergeCDataSections = settings.MergeCDataSections; this.closeOutput = closeOutput; if ( checkCharacters && newLineHandling == NewLineHandling.Replace ) { ValidateContentChars( newLineChars, "NewLineChars", false ); } }