示例#1
0
		/// <summary>
		/// The "oldFileReader" parameter allows the LdmldataMapper to allow data that it doesn't understand to be roundtripped.
		/// </summary>
		/// <param name="xmlWriter"></param>
		/// <param name="ws"></param>
		/// <param name="oldFileReader"></param>
		public void Write(XmlWriter xmlWriter, WritingSystemDefinition ws, XmlReader oldFileReader)
		{
			if (xmlWriter == null)
			{
				throw new ArgumentNullException("xmlWriter");
			}
			if (ws == null)
			{
				throw new ArgumentNullException("ws");
			}
			// We don't want to run any risk of persisting an invalid writing system in an LDML.
			string message;
			if (!ws.ValidateLanguageTag(out message))
				throw new ArgumentException(string.Format("The writing system's IETF language tag is invalid: {0}", message), "ws");
			XElement element = oldFileReader != null ? XElement.Load(oldFileReader) : new XElement("ldml");
			WriteLdml(xmlWriter, element, ws);
		}
示例#2
0
		/// <summary>
		/// The "oldFile" parameter allows the LdmldataMapper to allow data that it doesn't understand to be roundtripped.
		/// </summary>
		/// <param name="filePath"></param>
		/// <param name="ws"></param>
		/// <param name="oldFile"></param>
		public void Write(string filePath, WritingSystemDefinition ws, Stream oldFile)
		{
			if (filePath == null)
			{
				throw new ArgumentNullException("filePath");
			}
			if (ws == null)
			{
				throw new ArgumentNullException("ws");
			}
			// We don't want to run any risk of persisting an invalid writing system in an LDML.
			string message;
			if (!ws.ValidateLanguageTag(out message))
				throw new ArgumentException(string.Format("The writing system's IETF language tag is invalid: {0}", message), "ws");
			XmlReader reader = null;
			try
			{
				XElement element;
				if (oldFile != null)
				{
					var readerSettings = new XmlReaderSettings
					{
						IgnoreWhitespace = true,
						ConformanceLevel = ConformanceLevel.Auto,
						ValidationType = ValidationType.None,
						XmlResolver = null,
						DtdProcessing = DtdProcessing.Parse
					};
					reader = XmlReader.Create(oldFile, readerSettings);
					element = XElement.Load(reader);
				}
				else
				{
					element = new XElement("ldml");
				}
				// Use Canonical xml settings suitable for use in Chorus applications
				// except NewLineOnAttributes to conform to SLDR files
				var writerSettings = CanonicalXmlSettings.CreateXmlWriterSettings();
				writerSettings.NewLineOnAttributes = false;
				using (var writer = XmlWriter.Create(filePath, writerSettings))
				{
					WriteLdml(writer, element, ws);
					writer.Close();
				}
			}
			finally
			{
				if (reader != null)
				{
					reader.Close();
				}
			}
		}