本文整理匯總了C#中System.Xml.XmlTextWriter.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextWriter.ToString方法的具體用法?C# XmlTextWriter.ToString怎麽用?C# XmlTextWriter.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.ToString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Serialize
public XmlNode Serialize(object value)
{
XmlSerializer ser = new XmlSerializer(value.GetType());
// Serialize object to xml
StringWriter sw = new StringWriter( System.Globalization.CultureInfo.CurrentUICulture );
XmlTextWriter writer = new XmlTextWriter( sw );
ser.Serialize( writer, value );
writer.Flush();
// Return as a XmlNode
XmlDocument doc = new XmlDocument();
doc.LoadXml( writer.ToString() );
return doc.DocumentElement;
}
示例2: GrabInnerText
/// <summary>
/// Takes the contents of an <see cref="IUPnPMedia"/> object
/// casts the data into its XML string form and returns it.
/// </summary>
/// <param name="entry">the object to extract</param>
/// <returns>everything under the item or container element</returns>
private string GrabInnerText(IUPnPMedia entry)
{
StringBuilder sb = new StringBuilder(1000);
StringWriter sw = new StringWriter(sb);
XmlTextWriter xmlWriter = new XmlTextWriter(sw);
// set up the ToXml() method to only provide the InnerText of the element
entry.ToXml(ToXmlFormatter.DefaultFormatter, MediaObject.ToXmlData_AllInnerTextOnly, xmlWriter);
xmlWriter.Flush();
string result = xmlWriter.ToString();
xmlWriter.Close();
return result;
}
示例3: GenerateEntityXml
public static string GenerateEntityXml(string outputPath, EntityInfo entity)
{
string ret = String.Empty;
if (entity == null || !Directory.Exists(outputPath))
return ret;
Log4Helper.Write("GenerateEntityXml", String.Format("Process of entity {0} starts at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);
using (System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(System.IO.Path.Combine(outputPath, String.Concat(entity.ClassName, ".xml")), System.Text.Encoding.UTF8))
{
xtw.Formatting = System.Xml.Formatting.Indented;
xtw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
//generate entity calss
xtw.WriteStartElement("entity");
xtw.WriteAttributeString("namespace", entity.NameSpace);
xtw.WriteAttributeString("name", entity.ClassName);
#region columns/properties
//generate property node
xtw.WriteStartElement("fields");
foreach (FieldInfo field in entity.Fileds)
{
xtw.WriteStartElement("property");
xtw.WriteAttributeString("type", field.Type);
xtw.WriteAttributeString("name", field.Name);
xtw.WriteAttributeString("privateFieldName", field.PrivateFieldName);
xtw.WriteAttributeString("paramName", field.ParamName);
xtw.WriteAttributeString("propetyName", field.PropertyName);
xtw.WriteAttributeString("csharpType", field.CSharpType);
xtw.WriteEndElement();
}
xtw.WriteEndElement();
#endregion
ret = xtw.ToString();
xtw.WriteEndElement();
xtw.Flush();
xtw.Close();
}
Log4Helper.Write("GenerateEntityXmlFromTable", String.Format("Process of table {0} ends at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);
return ret;
}
示例4: Render
public virtual String Render() {
try {
StringWriter sw = new StringWriter();
XmlTextWriter tw = new XmlTextWriter(sw);
element.WriteContentTo(tw);
return tw.ToString();
} catch (System.Exception e) {}
return "";
}
示例5: SaveQueryXML
private void SaveQueryXML(string directory, string fileName)
{
XmlDocument xd = new XmlDocument();
TextWriter tw = new StringWriter();
//userQuery.Serialize();
if (operatorListGraphic.Count != 0)
{
//MessageBox.Show(operatorListGraphic.Count.ToString());
for (int i = 0; i < operatorListGraphic.Count; i++)
{
switch (operatorListGraphic[i].Type.ToString())
{
case "Select":
MessageBox.Show("Select");
Query s = new OpGenerate(100);
Query q = new OpSelect("$1.1 > 4", s);
q.SerializeOp(tw);
XmlTextWriter xw = new XmlTextWriter(tw);
MessageBox.Show(tw.ToString());
MessageBox.Show(xw.ToString());
break;
case "Project":
MessageBox.Show("Project");
break;
case "Union":
MessageBox.Show("Union");
break;
case "Intersection":
MessageBox.Show("Intersection");
break;
case "Join":
MessageBox.Show("Join");
break;
case "Difference":
MessageBox.Show("Difference");
break;
case "Generate":
MessageBox.Show("Generate");
break;
case "Sort":
MessageBox.Show("Sort");
break;
case "GroupBy":
MessageBox.Show("Group-by");
break;
case "DupElim":
MessageBox.Show("Duplicate Elimination");
break;
case "InputStream":
MessageBox.Show("Input Stream");
break;
case "OutputStream":
MessageBox.Show("Output Stream");
break;
default:
break;
};
}
}
else
{
//Write empty XML file.
MessageBox.Show("No Operators in Build Area!");
}
}
示例6: Serialization
public void Serialization()
{
try {
XmlDiff diff = new XmlDiff();
TemplateBox templateBox = new TemplateBox(TemplatingResources.TemplatesDefault);
String result = templateBox.Serialize();
//Utils.WriteToFile(@"C:\temp\templates.xml", result);
diff.IgnoreChildOrder = true;
diff.IgnoreComments = true;
diff.IgnoreDtd = true;
diff.IgnoreNamespaces = true;
diff.IgnorePI = true;
diff.IgnorePrefixes = true;
diff.IgnoreWhitespace = true;
diff.IgnoreXmlDecl = true;
StringWriter diffgramString = new StringWriter();
XmlTextWriter diffgramXml = new XmlTextWriter(diffgramString);
bool diffBool = diff.Compare(new XmlTextReader(new StringReader(result)), new XmlTextReader(new StringReader(TemplatingResources.TemplatesDefault)), diffgramXml);
//MessageBox.Show(diffgramString.ToString());
Assert.True(diffBool, diffgramXml.ToString());
} catch (Exception e) {
Assert.Fail("Exception: " + e.GetType().Name + "\n" + e.Message + "\n" + e.StackTrace);
}
}