本文整理汇总了C#中XmlWriterSettings类的典型用法代码示例。如果您正苦于以下问题:C# XmlWriterSettings类的具体用法?C# XmlWriterSettings怎么用?C# XmlWriterSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlWriterSettings类属于命名空间,在下文中一共展示了XmlWriterSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var pathSVGIcons = Server.MapPath("~/Composite/images/icons/svg/");
XNamespace svgNamespace = @"http://www.w3.org/2000/svg";
var svgSprite = XElement.Parse(svgBlank);
var defs = svgSprite.Descendants(svgNamespace + "defs").First();
foreach (var file in Directory.GetFiles(pathSVGIcons))
{
var id = Path.GetFileNameWithoutExtension(file);
var svgElement = XElement.Load(file);
var taggetGroup = svgElement.Descendants(svgNamespace + "g").FirstOrDefault(el => (string) el.Attribute("id") == id);
if (taggetGroup != null)
{
defs.Add(taggetGroup);
}
}
var settings = new XmlWriterSettings {OmitXmlDeclaration = true};
using (XmlWriter xw = XmlWriter.Create(PathUtil.Resolve("~/Composite/images/sprite.svg"), settings))
{
svgSprite.Save(xw);
}
}
示例2: Start
// Use this for initialization
void Start()
{
playerData = new PlayerData1("PkerkidHD", 10.0f);
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings()
{
Indent = true,
IndentChars = "\t",
NewLineOnAttributes = true
};
using (XmlWriter xml = XmlWriter.Create("PlayerData.xml", xmlWriterSettings)) {
//ROOT
xml.WriteStartDocument();
xml.WriteStartElement("PlayerData");
xml.WriteStartElement("Player");
xml.WriteElementString("PlayerName", playerData.PlayerName);
xml.WriteElementString("Money", playerData.Money.ToString());
xml.WriteEndElement();
// End.
xml.WriteEndElement();
xml.WriteEndDocument();
xml.Flush();
}
Debug.Log ("DONE");
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTime dt = new DateTime();
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.IndentChars=(" ");
xws.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter xwr = XmlWriter.Create(Server.MapPath("stu.xml"), xws);
try
{
xwr.WriteStartElement("userinfo");
xwr.WriteStartElement("user");
xwr.WriteElementString("name","zhangsan");
xwr.WriteEndElement();
xwr.WriteStartElement("user");
xwr.WriteElementString("name", "Jim john");
xwr.WriteEndElement();
xwr.WriteStartElement("user");
xwr.WriteElementString("name", "Marry");
xwr.WriteEndElement();
xwr.WriteEndElement();
xwr.Flush();
xwr.Close();
}
catch (Exception ex)
{
xwr.Close();
TextBox2.Text=ex.Message.ToString();
}
}
mydom.Load(Server.MapPath("cat1.xml"));
}
示例4: Transform
public static string Transform(string xsltFile, string xml, XsltArgumentList xslArg)
{
string result = "";
try {
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xsltFile);
// XmlWriterSettings.OmitXmlDeclaration
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(new StringReader(xml));
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
using (StringWriter sw = new StringWriter()) {
using (XmlWriter writer = XmlWriter.Create(sw, settings)) {
xslt.Transform(xmlDoc, xslArg, writer);
}
sw.Flush();
result = sw.ToString();
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
return result;
}
示例5: ToXml
internal static string ToXml(this object item)
{
if (item == null)
return null;
try
{
using (var stream = new StringWriter())
{
var settings = new XmlWriterSettings();
settings.Indent = false;
settings.OmitXmlDeclaration = true;
using (var writer = XmlWriter.Create(stream, settings))
{
var serializer = new XmlSerializer(item.GetType());
var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
serializer.Serialize(writer, item, emptyNamepsaces);
return stream.ToString();
}
}
}
catch
{
throw;
}
}
示例6: Main
public static void Main(string[] args)
{
AtomXmlReader reader = new AtomXmlReader();
reader.DocumentTypeDetected += delegate(object sender, DocumentTypeDetectedEventArgs e) {
if (!e.DocumentType.IsAssignableFrom(typeof(AtomEntry))) {
e.HaltFurtherProcess = true;
}
};
try {
if (args.Length == 0) {
Stream input = Console.OpenStandardInput();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
reader.ReadDocument(input).WriteDocument(Console.Out, settings);
}
else {
foreach (string feedLocation in args) {
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
reader.ReadDocument(feedLocation).WriteDocument(Console.Out, settings);
break;
}
}
}
catch (ArgumentException e) {
Console.Error.WriteLine(e.Message);
}
}
示例7: Start
// Use this for initialization
void Start()
{
cardList.Add(new CreatureCard());
cardList.Add(new CreatureCard("アリスに化けたマミゾウ"));
XmlSerializer xmls = new XmlSerializer(typeof(List<CreatureCard>));
XmlWriterSettings settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true };
using (var stream = File.OpenWrite("cardList.xml"))
{
using (var xmlWriter = XmlWriter.Create(stream, settings))
{
xmls.Serialize(xmlWriter, cardList);
}
}
Type[] extraTypes = { typeof(Land), typeof(LiveableLand) };
xmls = new XmlSerializer(typeof(Map),extraTypes);
using (var stream = File.OpenWrite("map.xml"))
{
using (var xmlWriter = XmlWriter.Create(stream, settings))
{
xmls.Serialize(xmlWriter, map);
}
}
}
示例8: Awake
void Awake(){
player1HandPosition = GameObject.Find ("Canvas/Player1Hand");
CL = GameObject.Find ("CardLoader").GetComponent<CardLoader>();
using (XmlReader reader = XmlReader.Create (new StreamReader (Application.persistentDataPath + "/Decks/DeckList.xml"))) {
XmlWriterSettings ws = new XmlWriterSettings ();
ws.Indent = true;
while (reader.Read ()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
switch (reader.Name) {
case "Deck":
deckName = reader.GetAttribute ("Name");
//Debug.Log (deckName);
break;
}
break;
case XmlNodeType.Text:
//Debug.Log (reader.Value);
line = reader.Value;
break;
}
}
}
player1Deck = line.Split (',').ToList<string> ();
player1Deck.RemoveAt (player1Deck.Count - 1); // Remove the blank string at the end of the list of cards
RandomizeDeck(player1Deck);
DrawStartingHands (player1Deck);
//Debug.Log (player1Deck.Count);
DisplayHand(player1HandPosition, player1Hand);
}
示例9: XmlWriterTraceListener
public XmlWriterTraceListener (TextWriter writer, string name)
: base (writer, name)
{
XmlWriterSettings settings = new XmlWriterSettings ();
settings.OmitXmlDeclaration = true;
w = XmlWriter.Create (writer, settings);
}
示例10: SaveGame
public void SaveGame(string savePath){
//Create a folder for saves incase it does not already exist
string saveFolder = Directory.GetCurrentDirectory () + "/Saves";
if (!Directory.Exists (saveFolder))
Directory.CreateDirectory (saveFolder);
//Setup Xml writer and file-stream
XmlWriterSettings ws = new XmlWriterSettings ();
ws.Indent = true;
ws.Encoding = Encoding.UTF8;
//Setup the writer and ouptut
using (FileStream fs = new FileStream (saveFolder + '/' + savePath + ".xml", FileMode.Create)) {
using (XmlWriter writer = XmlWriter.Create (fs, ws)) {
//Write start of document
writer.WriteStartDocument ();
writer.WriteStartElement ("Save");
//Add things to save here!
_player.GetComponent<Wizard> ().Save (writer);
SaveEnemies (writer);
writer.WriteEndElement ();
writer.WriteEndDocument ();
}
}
}
示例11: DisposeFlushesAndDisposesOutputStream
public static void DisposeFlushesAndDisposesOutputStream()
{
bool[] asyncValues = { false, true };
bool[] closeOutputValues = { false, true };
bool[] indentValues = { false, true };
bool[] omitXmlDeclarationValues = { false, true };
bool[] writeEndDocumentOnCloseValues = { false, true };
foreach (var async in asyncValues)
foreach (var closeOutput in closeOutputValues)
foreach (var indent in indentValues)
foreach (var omitXmlDeclaration in omitXmlDeclarationValues)
foreach (var writeEndDocumentOnClose in writeEndDocumentOnCloseValues)
{
using (MemoryStream ms = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
// UTF8 without BOM
settings.Encoding = new UTF8Encoding(false);
settings.Async = async;
settings.CloseOutput = closeOutput;
settings.Indent = indent;
settings.OmitXmlDeclaration = omitXmlDeclaration;
settings.WriteEndDocumentOnClose = writeEndDocumentOnClose;
XmlWriter writer = XmlWriter.Create(ms, settings);
writer.WriteStartDocument();
writer.WriteStartElement("root");
writer.WriteStartElement("test");
writer.WriteString("abc");
// !!! intentionally not closing both elements
// !!! writer.WriteEndElement();
// !!! writer.WriteEndElement();
writer.Dispose();
if (closeOutput)
{
bool failed = true;
try
{
ms.WriteByte(123);
}
catch (ObjectDisposedException) { failed = false; }
if (failed)
{
throw new Exception("Failed!");
}
}
else
{
string output = ReadAsString(ms);
Assert.True(output.Contains("<test>abc"));
Assert.NotEqual(output.Contains("<?xml version"), omitXmlDeclaration);
Assert.Equal(output.Contains(" "), indent);
Assert.Equal(output.Contains("</test>"), writeEndDocumentOnClose);
}
// should not throw
writer.Dispose();
}
}
}
示例12: default_2
//[Variation(id=2, Desc="Default value of OmitXmlDeclaration")]
public int default_2()
{
XmlWriterSettings wSettings = new XmlWriterSettings();
CError.Compare(wSettings.OmitXmlDeclaration, false, "Incorrect default value of OmitXmlDeclaration");
return TEST_PASS;
}
示例13: XmlQueryStaticData
/// <summary>
/// Constructor.
/// </summary>
public XmlQueryStaticData(XmlWriterSettings defaultWriterSettings, IList<WhitespaceRule> whitespaceRules, StaticDataManager staticData)
{
Debug.Assert(defaultWriterSettings != null && staticData != null);
_defaultWriterSettings = defaultWriterSettings;
_whitespaceRules = whitespaceRules;
_names = staticData.Names;
_prefixMappingsList = staticData.PrefixMappingsList;
_filters = staticData.NameFilters;
_types = staticData.XmlTypes;
_collations = staticData.Collations;
_globalNames = staticData.GlobalNames;
_earlyBound = staticData.EarlyBound;
#if DEBUG
// Round-trip check
byte[] data;
Type[] ebTypes;
this.GetObjectData(out data, out ebTypes);
XmlQueryStaticData copy = new XmlQueryStaticData(data, ebTypes);
_defaultWriterSettings = copy._defaultWriterSettings;
_whitespaceRules = copy._whitespaceRules;
_names = copy._names;
_prefixMappingsList = copy._prefixMappingsList;
_filters = copy._filters;
_types = copy._types;
_collations = copy._collations;
_globalNames = copy._globalNames;
_earlyBound = copy._earlyBound;
#endif
}
示例14: SaveXmlLevel
public static void SaveXmlLevel(ABLevel level) {
StringBuilder output = new StringBuilder();
XmlWriterSettings ws = new XmlWriterSettings();
ws.Indent = true;
using (XmlWriter writer = XmlWriter.Create(output, ws))
{
writer.WriteStartElement("Level");
writer.WriteStartElement("BirdsAmount");
writer.WriteValue(level.birdsAmount);
writer.WriteEndElement();
writer.WriteStartElement("GameObjects");
foreach(ABGameObject abObj in level.gameObjects)
{
writer.WriteStartElement("GameObject");
writer.WriteAttributeString("label", abObj.Label.ToString());
writer.WriteAttributeString("x", abObj.Position.x.ToString());
writer.WriteAttributeString("y", abObj.Position.y.ToString());
writer.WriteEndElement();
}
}
int levelsAmountInResources = LoadAllLevels().Length;
StreamWriter streamWriter = new StreamWriter("Assets/Resources/GeneratedLevels/genetic-level-" + (levelsAmountInResources + 1) + ".xml");
streamWriter.WriteLine(output.ToString());
streamWriter.Close();
}
示例15: WriteWithEncoding
public static void WriteWithEncoding()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;
settings.Encoding = Encoding.GetEncoding("Windows-1252");
MemoryStream strm = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(strm, settings))
{
writer.WriteElementString("orderID", "1-456-ab\u0661");
writer.WriteElementString("orderID", "2-36-00a\uD800\uDC00\uD801\uDC01");
writer.Flush();
}
strm.Seek(0, SeekOrigin.Begin);
byte[] bytes = new byte[strm.Length];
int bytesCount = strm.Read(bytes, 0, (int)strm.Length);
string s = settings.Encoding.GetString(bytes, 0, bytesCount);
Assert.Equal("<orderID>1-456-ab١</orderID><orderID>2-36-00a𐀀𐐁</orderID>", s);
}