本文整理汇总了C#中System.Xml.XmlTextWriter.WriteString方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter.WriteString方法的具体用法?C# System.Xml.XmlTextWriter.WriteString怎么用?C# System.Xml.XmlTextWriter.WriteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了System.Xml.XmlTextWriter.WriteString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ask
public void Ask(SelectableSource source, TextWriter output)
{
bool result = Ask(source);
if (MimeType == SparqlXmlQuerySink.MimeType || MimeType == "text/xml") {
System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(output);
w.Formatting = System.Xml.Formatting.Indented;
w.WriteStartElement("sparql");
w.WriteAttributeString("xmlns", "http://www.w3.org/2001/sw/DataAccess/rf1/result");
w.WriteStartElement("head");
w.WriteEndElement();
w.WriteStartElement("boolean");
w.WriteString(result ? "true" : "false");
w.WriteEndElement();
w.WriteEndElement();
w.Flush();
} else if (MimeType == "text/plain") {
output.WriteLine(result ? "true" : "false");
} else {
}
}
示例2: Ask
public void Ask(SelectableSource source, TextWriter output) {
bool result = Ask(source);
System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(output);
w.Formatting = System.Xml.Formatting.Indented;
w.WriteStartElement("sparql");
w.WriteAttributeString("xmlns", "http://www.w3.org/2001/sw/DataAccess/rf1/result");
w.WriteStartElement("head");
w.WriteEndElement();
w.WriteStartElement("results");
w.WriteStartElement("boolean");
w.WriteString(result ? "true" : "false");
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.Close();
}
示例3: Append
/// <summary>
/// ��¼�쳣��Ϣ��XML�ļ��С�
/// </summary>
/// <param name="ex">�쳣��</param>
/// <returns>��¼�ɹ�����True����¼ʧ�ܷ���False</returns>
public static void Append(System.Exception ex)
{
if (System.IO.File.Exists(Path))
{
System.Xml.XmlDocument xd;
System.Xml.XmlNode node;
System.Xml.XmlElement xe;
xd = new System.Xml.XmlDocument();
xd.Load(Path);
node = xd.SelectSingleNode("ROOT");
xe = xd.CreateElement("Exception");
node = node.AppendChild(xe);
xe = xd.CreateElement("OccurDate");
xe.InnerText = System.DateTime.Now.ToString();
node.AppendChild(xe);
xe = xd.CreateElement("Source");
xe.InnerText = ex.Source;
node.AppendChild(xe);
xe = xd.CreateElement("HelpLink");
xe.InnerText = ex.HelpLink;
node.AppendChild(xe);
xe = xd.CreateElement("TargetSiteName");
xe.InnerText = ex.TargetSite.Name;
node.AppendChild(xe);
xe = xd.CreateElement("StackTrace");
xe.InnerText = ex.StackTrace;
node.AppendChild(xe);
xe = xd.CreateElement("Message");
xe.InnerText = ex.Message;
node.AppendChild(xe);
xd.Save(Path);
}
else
{
System.Xml.XmlTextWriter xtw;
xtw = new System.Xml.XmlTextWriter(Path, System.Text.Encoding.UTF8);
xtw.Formatting = System.Xml.Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement("ROOT");
xtw.WriteStartElement("Exception");
xtw.WriteStartElement("OccurDate");
xtw.WriteString(System.DateTime.Now.ToString());
xtw.WriteEndElement();
xtw.WriteStartElement("Source");
xtw.WriteString(ex.Source);
xtw.WriteEndElement();
xtw.WriteStartElement("HelpLink");
xtw.WriteString(ex.HelpLink);
xtw.WriteEndElement();
xtw.WriteStartElement("TargetSiteName");
xtw.WriteString(ex.TargetSite.Name);
xtw.WriteEndElement();
xtw.WriteStartElement("StackTrace");
xtw.WriteString(ex.StackTrace);
xtw.WriteEndElement();
xtw.WriteStartElement("Message");
xtw.WriteString(ex.Message);
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.Flush();
xtw.Close();
}
}
示例4: WriteUserSetting
public void WriteUserSetting(string SectionName, string EntryName, string EntryValue)
{
// Make sure all of the necessary information was passed to this routine before attempting to write to
// the Settings File.
if (SectionName == null || SectionName == "" || EntryName == null || EntryName == "" || EntryValue == "")
{
// Exit the Method.
return;
}
try
{
// If the value is null, remove the entry
if (EntryValue == null)
{
RemoveUserSetting(SectionName, EntryValue);
return;
}
// Verify that the file is available for reading and that the XML Section and Entry Name values are valid.
VerifyNotReadOnly();
string section = SectionName;
VerifyAndAdjustSection(ref section);
string entry = EntryName;
VerifyAndAdjustEntry(ref entry);
// If the File does not exist, create it.
if (System.IO.File.Exists(_filePath))
{
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(_filePath, System.Text.Encoding.UTF8);
writer.Formatting = System.Xml.Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("profile");
writer.WriteStartElement("section");
writer.WriteAttributeString("name", null, section);
writer.WriteStartElement("entry");
writer.WriteAttributeString("name", null, entry);
writer.WriteString(EntryValue);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
// Exit the method now that the file has been created.
return;
}
// The file exists, edit it
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(_filePath);
System.Xml.XmlElement root = doc.DocumentElement;
// Get the section element and add it if it's not there
System.Xml.XmlNode sectionNode = root.SelectSingleNode(GetSectionsPath(section));
if (sectionNode == null)
{
System.Xml.XmlElement element = doc.CreateElement("section");
System.Xml.XmlAttribute attribute = doc.CreateAttribute("name");
attribute.Value = section;
element.Attributes.Append(attribute);
sectionNode = root.AppendChild(element);
}
// Get the entry element and add it if it's not there
System.Xml.XmlNode entryNode = sectionNode.SelectSingleNode(GetEntryPath(entry));
if (entryNode == null)
{
System.Xml.XmlElement element = doc.CreateElement("entry");
System.Xml.XmlAttribute attribute = doc.CreateAttribute("name");
attribute.Value = entry;
element.Attributes.Append(attribute);
entryNode = sectionNode.AppendChild(element);
}
// Add the value and save the file
entryNode.InnerText = EntryValue;
doc.Save(_filePath);
}
catch
{
// Exit this Method.
return;
}
}
示例5: Run
public void Run()
{
geneticfx.Environment env = new geneticfx.Environment( );
env.StartGeneration+= new geneticfx.Environment.EventHandlerDelegate( this.StartGenerationHandler );
env.EndGeneration+= new geneticfx.Environment.EventHandlerDelegate( this.EndGenerationHandler );
geneticfx.Population initial_population = new geneticfx.Population( 50 );
System.Collections.ArrayList rects = new System.Collections.ArrayList();
rects.Add( new RECT(0,0,100,100) );
rects.Add( new RECT(0,0,100,200) );
rects.Add( new RECT(0,0,200,100) );
rects.Add( new RECT(0,0,200,200) );
rects.Add( new RECT(0,0,200,100) );
rects.Add( new RECT(0,0,200,200) );
rects.Add( new RECT(0,0,100,100) );
rects.Add( new RECT(0,0,100,200) );
rects.Add( new RECT(0,0,100,100) );
rects.Add( new RECT(0,0,100,200) );
rects.Add( new RECT(0,0,100,100) );
rects.Add( new RECT(0,0,100,200) );
for (int i=0;i<initial_population.Capacity;i++)
{
MyChromosome cs = new MyChromosome( rects );
cs.RandomizeGenes();
geneticfx.Organism o = new geneticfx.Organism( cs, 0.0F );
initial_population.AddOrganism(o);
}
env.MutationRate = 0.10F;
int num_generations=10;
env.SetupForEvolution( initial_population , geneticfx.FitnessDirection.Minimize);
string fname ="out.svg";
fname = System.IO.Path.GetFullPath( fname );
System.Xml.XmlWriter xw = new System.Xml.XmlTextWriter( fname, System.Text.Encoding.UTF8 );
xw.WriteStartElement("svg");
int cur_y = 100;
for (int i=0;i<num_generations;i++)
{
env.EvolveNextGeneration();
geneticfx.Generation generation = env.CurrentGeneration;
int cur_x = 100;
for (int generation_index=0;generation_index<generation.population.Size;generation_index++)
{
geneticfx.Organism o = generation.population[ generation_index ];
MyChromosome mcr = (MyChromosome) o.Genes;
RECT bb = RECTTOOLS.get_bounding_box( mcr.layout_rects );
xw.WriteStartElement("g");
xw.WriteAttributeString( "transform", string.Format( "translate({0},{1})", cur_x, cur_y ) );
for (int icr=0;icr<mcr.Length;icr++)
{
RECT r = mcr.layout_rects [icr];
xw.WriteStartElement("rect");
xw.WriteAttributeString( "x", r.x0.ToString() );
xw.WriteAttributeString( "y", r.y0.ToString());
xw.WriteAttributeString( "width", r.w.ToString());
xw.WriteAttributeString( "height", r.h.ToString() );
xw.WriteAttributeString( "opacity", "0.1");
xw.WriteEndElement();
xw.WriteStartElement("text");
xw.WriteAttributeString( "x", "0" );
xw.WriteAttributeString( "y", "0" );
string s = string.Format( "Gen{0} / Org{1} / Fit={2}", generation_index,o.ID,o.Fitness );
xw.WriteString( s );
xw.WriteEndElement();
}
xw.WriteEndElement();
cur_x += (int) (1000 + 100);
}
cur_y += (int) (1000 + 100);
xw.Flush();
}
xw.WriteEndElement();
xw.Flush();
xw.Close();
}