本文整理汇总了C#中System.Xml.XmlDocument.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlDocument.WriteTo方法的具体用法?C# System.Xml.XmlDocument.WriteTo怎么用?C# System.Xml.XmlDocument.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了System.Xml.XmlDocument.WriteTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateConfig
/// <summary>
/// 保存Config参数
/// </summary>
public static void UpdateConfig(string name, string nKey, string nValue)
{
if (ReadConfig(name, nKey) != "")
{
System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
XmlDoc.Load(HttpContext.Current.Server.MapPath(name + ".config"));
System.Xml.XmlNodeList elemList = XmlDoc.GetElementsByTagName(nKey);
System.Xml.XmlNode mNode = elemList[0];
mNode.InnerText = nValue;
System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(new System.IO.StreamWriter(HttpContext.Current.Server.MapPath(name + ".config")));
xw.Formatting = System.Xml.Formatting.Indented;
XmlDoc.WriteTo(xw);
xw.Close();
}
}
示例2: WriteToStream
protected virtual void WriteToStream(System.IO.Stream stream, PersistenceFlags flags)
{
// System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
//
// writer.Formatting = System.Xml.Formatting.Indented;
// writer.WriteStartDocument();
// writer.WriteStartElement("settings");
//
// writer.WriteStartElement("items");
// writer.WriteAttributeString("schemaversion", "1");
//
// foreach (PersistableItem item in m_Dictionary.Values)
// {
// if ( (flags & PersistenceFlags.OnlyChanges) == PersistenceFlags.OnlyChanges &&
// item.IsChanged == false)
// continue;
//
// writer.WriteStartElement("item");
// writer.WriteAttributeString("name", item.Name);
// writer.WriteAttributeString("type", item.Type.FullName);
// writer.WriteAttributeString("schemaversion", "1");
// writer.WriteString(item.Validator.ValueToString(item.Value));
// writer.WriteEndElement();
// }
//
// writer.WriteEndElement();
//
// writer.WriteEndElement();
// writer.WriteEndDocument();
// writer.Flush();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.AppendChild(doc.CreateElement("settings"));
WriteToXmlElement(doc.DocumentElement, flags);
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
writer.Formatting = System.Xml.Formatting.Indented;
doc.WriteTo(writer);
writer.Flush();
}
示例3: Write
//.........这里部分代码省略.........
foreach (var assembly in this.BamAssemblies)
{
var assemblyElement = document.CreateElement("BamAssembly", namespaceURI);
assemblyElement.SetAttribute("name", assembly.Name);
if (assembly.MajorVersion.HasValue)
{
assemblyElement.SetAttribute("major", assembly.MajorVersion.ToString());
if (assembly.MinorVersion.HasValue)
{
assemblyElement.SetAttribute("minor", assembly.MinorVersion.ToString());
if (assembly.PatchVersion.HasValue)
{
// honour any existing BamAssembly with a specific patch version
assemblyElement.SetAttribute("patch", assembly.PatchVersion.ToString());
}
}
}
requiredAssemblies.AppendChild(assemblyElement);
}
packageDefinition.AppendChild(requiredAssemblies);
}
if (this.DotNetAssemblies.Count > 0)
{
var requiredDotNetAssemblies = document.CreateElement("DotNetAssemblies", namespaceURI);
foreach (var desc in this.DotNetAssemblies)
{
var assemblyElement = document.CreateElement("DotNetAssembly", namespaceURI);
assemblyElement.SetAttribute("name", desc.Name);
if (null != desc.RequiredTargetFramework)
{
assemblyElement.SetAttribute("requiredTargetFramework", desc.RequiredTargetFramework);
}
requiredDotNetAssemblies.AppendChild(assemblyElement);
}
packageDefinition.AppendChild(requiredDotNetAssemblies);
}
// supported platforms
{
var supportedPlatformsElement = document.CreateElement("SupportedPlatforms", namespaceURI);
if (EPlatform.Windows == (this.SupportedPlatforms & EPlatform.Windows))
{
var platformElement = document.CreateElement("Platform", namespaceURI);
platformElement.SetAttribute("name", "Windows");
supportedPlatformsElement.AppendChild(platformElement);
}
if (EPlatform.Linux == (this.SupportedPlatforms & EPlatform.Linux))
{
var platformElement = document.CreateElement("Platform", namespaceURI);
platformElement.SetAttribute("name", "Linux");
supportedPlatformsElement.AppendChild(platformElement);
}
if (EPlatform.OSX == (this.SupportedPlatforms & EPlatform.OSX))
{
var platformElement = document.CreateElement("Platform", namespaceURI);
platformElement.SetAttribute("name", "OSX");
supportedPlatformsElement.AppendChild(platformElement);
}
packageDefinition.AppendChild(supportedPlatformsElement);
}
// definitions
this.Definitions.Remove(this.GetPackageDefinitionName());
if (this.Definitions.Count > 0)
{
var definitionsElement = document.CreateElement("Definitions", namespaceURI);
foreach (string define in this.Definitions)
{
var defineElement = document.CreateElement("Definition", namespaceURI);
defineElement.SetAttribute("name", define);
definitionsElement.AppendChild(defineElement);
}
packageDefinition.AppendChild(definitionsElement);
}
var xmlWriterSettings = new System.Xml.XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriterSettings.CloseOutput = true;
xmlWriterSettings.OmitXmlDeclaration = false;
xmlWriterSettings.NewLineOnAttributes = false;
xmlWriterSettings.NewLineChars = "\n";
xmlWriterSettings.ConformanceLevel = System.Xml.ConformanceLevel.Document;
xmlWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
using (var xmlWriter = System.Xml.XmlWriter.Create(this.XMLFilename, xmlWriterSettings))
{
document.WriteTo(xmlWriter);
xmlWriter.WriteWhitespace(xmlWriterSettings.NewLineChars);
}
if (this.validate)
{
this.Validate();
}
}
示例4: RestartIISProcess
/// <summary>
/// hack tip:通过更新web.config文件方式来重启IIS进程池(注:iis中web园数量须大于1,且为非虚拟主机用户才可调用该方法)
/// </summary>
public static void RestartIISProcess() {
try {
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
xmldoc.Load("~/web.config".GetMapPath());
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter("~/web.config".GetMapPath(), null);
writer.Formatting = System.Xml.Formatting.Indented;
xmldoc.WriteTo(writer);
writer.Flush();
writer.Close();
} catch { ; }
}
示例5: Main
public static void Main(System.String[] args)
{
if (args.Length != 1)
{
System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file");
System.Environment.Exit(1);
}
//read and parse message from file
try
{
PipeParser parser = new PipeParser();
System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
long fileLength = SupportClass.FileLength(messageFile);
//UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
char[] cbuf = new char[(int) fileLength];
//UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'"
System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[]) cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
r.Close();
System.String messString = System.Convert.ToString(cbuf);
Message mess = parser.parse(messString);
System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);
ca.uhn.hl7v2.parser.XMLParser xp = new AnonymousClassXMLParser();
//loop through segment children of message, encode, print to console
System.String[] structNames = mess.Names;
for (int i = 0; i < structNames.Length; i++)
{
Structure[] reps = mess.getAll(structNames[i]);
for (int j = 0; j < reps.Length; j++)
{
if (typeof(Segment).IsAssignableFrom(reps[j].GetType()))
{
//ignore groups
//UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
//UPGRADE_ISSUE: Method 'javax.xml.parsers.DocumentBuilderFactory.newInstance' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersDocumentBuilderFactory'"
//DocumentBuilderFactory.newInstance();
System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
//UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment
System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName);
doc.AppendChild(root);
xp.encode((Segment) reps[j], root);
System.IO.StringWriter out_Renamed = new System.IO.StringWriter();
System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml);
System.Type[] segmentConstructTypes = new System.Type[]{typeof(Message)};
System.Object[] segmentConstructArgs = new System.Object[]{null};
Segment s = (Segment) reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs);
xp.parse(s, root);
//UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument();
System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName);
doc2.AppendChild(root2);
xp.encode(s, root2);
System.IO.StringWriter out2 = new System.IO.StringWriter();
System.Xml.XmlTextWriter ser = new System.Xml.XmlTextWriter(out2);
//System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2);
doc.WriteTo(ser);
if (out2.ToString().Equals(out_Renamed.ToString()))
{
System.Console.Out.WriteLine("Re-encode OK");
}
else
{
System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString());
}
}
}
}
}
catch (System.Exception e)
{
SupportClass.WriteStackTrace(e, Console.Error);
}
}
示例6: saveConfigurationToolStripMenuItem_Click
private void saveConfigurationToolStripMenuItem_Click(object sender, EventArgs e)
{
var xml = Brain.KB.ToXML();
var doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);
var sw = new System.IO.StringWriter();
var xtw = new System.Xml.XmlTextWriter(sw);
xtw.Formatting = System.Xml.Formatting.Indented;
doc.WriteTo(xtw);
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "KickBrain File|*.kickb";
saveFileDialog1.Title = "Save Configuration";
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName == "")
return;
System.IO.File.WriteAllText(saveFileDialog1.FileName, sw.ToString());
}
示例7: Serialize
public string Serialize()
{
var workspaceDoc = new System.Xml.XmlDocument();
var workspaceEl = workspaceDoc.CreateElement("Workspace");
workspaceEl.SetAttribute("version", "1.0");
workspaceDoc.AppendChild(workspaceEl);
var generateProjectSchemes = Bam.Core.CommandLineProcessor.Evaluate(new Options.GenerateXcodeSchemes());
foreach (var project in this.ProjectMap.Values)
{
project.FixupPerConfigurationData();
var text = new System.Text.StringBuilder();
text.AppendLine("// !$*UTF8*$!");
text.AppendLine("{");
var indentLevel = 1;
var indent = new string('\t', indentLevel);
text.AppendFormat("{0}archiveVersion = 1;", indent);
text.AppendLine();
text.AppendFormat("{0}classes = {{", indent);
text.AppendLine();
text.AppendFormat("{0}}};", indent);
text.AppendLine();
text.AppendFormat("{0}objectVersion = 46;", indent);
text.AppendLine();
text.AppendFormat("{0}objects = {{", indent);
text.AppendLine();
project.Serialize(text, indentLevel + 1);
text.AppendFormat("{0}}};", indent);
text.AppendLine();
text.AppendFormat("{0}rootObject = {1} /* Project object */;", indent, project.GUID);
text.AppendLine();
text.AppendLine("}");
var projectDir = project.ProjectDir;
if (!System.IO.Directory.Exists(projectDir.Parse()))
{
System.IO.Directory.CreateDirectory(projectDir.Parse());
}
//Bam.Core.Log.DebugMessage(text.ToString());
using (var writer = new System.IO.StreamWriter(project.ProjectPath))
{
writer.Write(text.ToString());
}
if (generateProjectSchemes)
{
var projectSchemeCache = new ProjectSchemeCache(project);
projectSchemeCache.Serialize();
}
var workspaceFileRef = workspaceDoc.CreateElement("FileRef");
workspaceFileRef.SetAttribute("location", System.String.Format("group:{0}", projectDir));
workspaceEl.AppendChild(workspaceFileRef);
}
var workspacePath = Bam.Core.TokenizedString.Create("$(buildroot)/$(masterpackagename).xcworkspace/contents.xcworkspacedata", null);
var workspaceDir = Bam.Core.TokenizedString.Create("@dir($(0))", null, positionalTokens: new Bam.Core.TokenizedStringArray(workspacePath));
var workspaceDirectory = workspaceDir.Parse();
if (!System.IO.Directory.Exists(workspaceDirectory))
{
System.IO.Directory.CreateDirectory(workspaceDirectory);
}
var settings = new System.Xml.XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Encoding = new System.Text.UTF8Encoding(false); // no BOM
settings.NewLineChars = System.Environment.NewLine;
settings.Indent = true;
settings.ConformanceLevel = System.Xml.ConformanceLevel.Document;
using (var xmlwriter = System.Xml.XmlWriter.Create(workspacePath.Parse(), settings))
{
workspaceDoc.WriteTo(xmlwriter);
}
return workspaceDirectory;
}
示例8: GetFormattedXmlString
private static string GetFormattedXmlString(string xml)
{
if (!string.IsNullOrEmpty(xml))
{
var xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xml);
using (var writer = new System.IO.StringWriter())
using (var xmlW = new System.Xml.XmlTextWriter(writer))
{
xmlW.Formatting = System.Xml.Formatting.Indented;
xmlDoc.WriteTo(xmlW);
xmlW.Flush();
return writer.ToString();
}
}
return null;
}
示例9: WriteResXFile
WriteResXFile(
string projectPath)
{
if (0 == Graph.Instance.Packages.Count())
{
throw new Exception("Package has not been specified. Run 'bam' from the package directory.");
}
var masterPackage = Graph.Instance.MasterPackage;
var projectDirectory = System.IO.Path.GetDirectoryName(projectPath);
if (!System.IO.Directory.Exists(projectDirectory))
{
System.IO.Directory.CreateDirectory(projectDirectory);
}
var resourceFilePathName = System.IO.Path.Combine(projectDirectory, "PackageInfoResources.resx");
var resourceFile = new System.Xml.XmlDocument();
var root = resourceFile.CreateElement("root");
resourceFile.AppendChild(root);
AddResHeader(resourceFile, "resmimetype", "text/microsoft-resx", root);
AddResHeader(resourceFile, "version", "2.0", root);
// TODO: this looks like the System.Windows.Forms.dll assembly
AddResHeader(resourceFile, "reader", "System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", root);
AddResHeader(resourceFile, "writer", "System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", root);
AddData(resourceFile, "BamInstallDir", Core.Graph.Instance.ProcessState.ExecutableDirectory, root);
// TODO: could be Core.Graph.Instance.ProcessState.WorkingDirectory?
AddData(resourceFile, "WorkingDir", masterPackage.GetPackageDirectory(), root);
var xmlWriterSettings = new System.Xml.XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriterSettings.CloseOutput = true;
xmlWriterSettings.OmitXmlDeclaration = true;
using (var xmlWriter = System.Xml.XmlWriter.Create(resourceFilePathName, xmlWriterSettings))
{
resourceFile.WriteTo(xmlWriter);
xmlWriter.WriteWhitespace(xmlWriterSettings.NewLineChars);
}
return resourceFilePathName;
}
示例10: Main
public static void Main(System.String[] args)
{
if (args.Length != 1)
{
System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file");
System.Environment.Exit(1);
}
//read and parse message from file
try
{
PipeParser parser = new PipeParser();
System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
long fileLength = SupportClass.FileLength(messageFile);
System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
char[] cbuf = new char[(int)fileLength];
System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
r.Close();
System.String messString = System.Convert.ToString(cbuf);
IMessage mess = parser.Parse(messString);
System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);
NHapi.Base.Parser.XMLParser xp = new AnonymousClassXMLParser();
//loop through segment children of message, encode, print to console
System.String[] structNames = mess.Names;
for (int i = 0; i < structNames.Length; i++)
{
IStructure[] reps = mess.GetAll(structNames[i]);
for (int j = 0; j < reps.Length; j++)
{
if (typeof(ISegment).IsAssignableFrom(reps[j].GetType()))
{
//ignore groups
System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment
System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName);
doc.AppendChild(root);
xp.Encode((ISegment)reps[j], root);
System.IO.StringWriter out_Renamed = new System.IO.StringWriter();
System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml);
System.Type[] segmentConstructTypes = new System.Type[] { typeof(IMessage) };
System.Object[] segmentConstructArgs = new System.Object[] { null };
ISegment s = (ISegment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs);
xp.Parse(s, root);
System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument();
System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName);
doc2.AppendChild(root2);
xp.Encode(s, root2);
System.IO.StringWriter out2 = new System.IO.StringWriter();
System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2);
doc.WriteTo(ser);
if (out2.ToString().Equals(out_Renamed.ToString()))
{
System.Console.Out.WriteLine("Re-encode OK");
}
else
{
System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString());
}
}
}
}
}
catch (System.Exception e)
{
SupportClass.WriteStackTrace(e, Console.Error);
}
}