本文整理汇总了C#中System.Xml.XmlDocument.CreateWhitespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateWhitespace方法的具体用法?C# XmlDocument.CreateWhitespace怎么用?C# XmlDocument.CreateWhitespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateWhitespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public bool Save(string path)
{
bool saved = true;
XmlDocument m_Xdoc = new XmlDocument();
try
{
m_Xdoc.RemoveAll();
XmlNode node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateComment($" Profile Configuration Data. {DateTime.Now} ");
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateWhitespace("\r\n");
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null);
m_Xdoc.AppendChild(node);
m_Xdoc.Save(path);
}
catch
{
saved = false;
}
return saved;
}
示例2: Save
public void Save(Control murpleControl, string filename, PodGroup thisPodGroup)
{
StreamWriter streamWriter = new StreamWriter(filename);
XmlWriter xmlWriter = XmlWriter.Create(streamWriter);
XmlDocument document = new XmlDocument();
document.AppendChild(document.CreateWhitespace("\n"));
{
XmlElement murpleElement = document.CreateElement("Murple");
AddNewLine(document, murpleElement);
foreach (KeyValuePair<System.Guid, Pod> thisPodPair in murpleControl.Pods)
{
if(thisPodGroup.ContainsPod(thisPodPair.Key) == true)
AddPod(document, murpleElement, thisPodPair);
}
document.AppendChild(murpleElement);
}
document.Save(xmlWriter);
streamWriter.Close();
}
示例3: GetReady
public void GetReady ()
{
document = new XmlDocument ();
document.LoadXml ("<root><foo></foo></root>");
XmlElement element = document.CreateElement ("foo");
whitespace = document.CreateWhitespace ("\r\n");
element.AppendChild (whitespace);
doc2 = new XmlDocument ();
doc2.PreserveWhitespace = true;
}
示例4: ImportWhiteSpace
public static void ImportWhiteSpace()
{
var whitespace = " ";
var tempDoc = new XmlDocument();
var nodeToImport = tempDoc.CreateWhitespace(whitespace);
var xmlDocument = new XmlDocument();
var node = xmlDocument.ImportNode(nodeToImport, true);
Assert.Equal(xmlDocument, node.OwnerDocument);
Assert.Equal(XmlNodeType.Whitespace, node.NodeType);
Assert.Equal(whitespace, node.Value);
}
示例5: AddPolygonToSvg
public void AddPolygonToSvg( XmlElement svgElement, XmlDocument htmlDoc )
{
XmlElement regionElement = htmlDoc.CreateElement ("g");
var regionNameAttr = htmlDoc.CreateAttribute("name");
regionNameAttr.Value = Name;
regionElement.Attributes.Append (regionNameAttr);
var regionClassAttr = htmlDoc.CreateAttribute ("class");
regionClassAttr.Value = "PoliticalRegion";
regionElement.Attributes.Append (regionClassAttr);
// Shape
for (int iSubRegion = 0; iSubRegion < Geometry.NumGeometries; iSubRegion += 1) {
var subRegionNode = htmlDoc.CreateElement ("polygon");
// Define subregion border.
var subRegion = Geometry.GetGeometryN (iSubRegion);
var coords = subRegion.Coordinates;
var coordStrings = coords.Select (coord => string.Format ("{0:F2},{1:F2} ", coord.X, -coord.Y));
string coordString = coordStrings.Aggregate ((coordStringBase, coordStringNext) => coordStringBase + coordStringNext);
var pointsAttr = htmlDoc.CreateAttribute ("points");
pointsAttr.Value = coordString;
subRegionNode.Attributes.Append(pointsAttr);
// Color/Style spec.
var styleAttr = htmlDoc.CreateAttribute ("style");
styleAttr.Value = StyleSpec;
subRegionNode.Attributes.Append(styleAttr);
// Add state polygon, text to list
regionElement.AppendChild (htmlDoc.CreateWhitespace ("\n"));
regionElement.AppendChild (subRegionNode);
}
// Add state polygon, text to list
svgElement.AppendChild (htmlDoc.CreateWhitespace ("\n"));
svgElement.AppendChild (regionElement);
}
示例6: CreateNode
public static XmlNode CreateNode(XmlDocument doc, XmlNodeType nodeType)
{
Assert.NotNull(doc);
switch (nodeType)
{
case XmlNodeType.CDATA:
return doc.CreateCDataSection(@"< & <tag> < ! > & </tag> ");
case XmlNodeType.Comment:
return doc.CreateComment(@"comment");
case XmlNodeType.Element:
return doc.CreateElement("E");
case XmlNodeType.Text:
return doc.CreateTextNode("text");
case XmlNodeType.Whitespace:
return doc.CreateWhitespace(@" ");
case XmlNodeType.SignificantWhitespace:
return doc.CreateSignificantWhitespace(" ");
default:
throw new ArgumentException("Wrong XmlNodeType: '" + nodeType + "'");
}
}
示例7: DeserializeValue
private void DeserializeValue(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, string propertyName, XmlNode currentNode)
{
switch (propertyName)
{
case TextName:
currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
break;
case CDataName:
currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
break;
case WhitespaceName:
currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
break;
case SignificantWhitespaceName:
currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
break;
default:
// processing instructions and the xml declaration start with ?
if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
{
if (propertyName == DeclarationName)
{
string version = null;
string encoding = null;
string standalone = null;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
switch (reader.Value.ToString())
{
case "@version":
reader.Read();
version = reader.Value.ToString();
break;
case "@encoding":
reader.Read();
encoding = reader.Value.ToString();
break;
case "@standalone":
reader.Read();
standalone = reader.Value.ToString();
break;
default:
throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
}
}
XmlDeclaration declaration = document.CreateXmlDeclaration(version, encoding, standalone);
currentNode.AppendChild(declaration);
}
else
{
XmlProcessingInstruction instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
currentNode.AppendChild(instruction);
}
}
else
{
// deserialize xml element
bool finishedAttributes = false;
bool finishedElement = false;
string elementPrefix = GetPrefix(propertyName);
Dictionary<string, string> attributeNameValues = new Dictionary<string, string>();
// a string token means the element only has a single text child
if (reader.TokenType != JsonToken.String
&& reader.TokenType != JsonToken.Null
&& reader.TokenType != JsonToken.Boolean
&& reader.TokenType != JsonToken.Integer
&& reader.TokenType != JsonToken.Float
&& reader.TokenType != JsonToken.Date
&& reader.TokenType != JsonToken.StartConstructor)
{
// read properties until first non-attribute is encountered
while (!finishedAttributes && !finishedElement && reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
string attributeName = reader.Value.ToString();
if (attributeName[0] == '@')
{
attributeName = attributeName.Substring(1);
reader.Read();
string attributeValue = reader.Value.ToString();
attributeNameValues.Add(attributeName, attributeValue);
string namespacePrefix;
if (IsNamespaceAttribute(attributeName, out namespacePrefix))
{
manager.AddNamespace(namespacePrefix, attributeValue);
}
}
else
{
finishedAttributes = true;
}
break;
case JsonToken.EndObject:
//.........这里部分代码省略.........
示例8: Detokenize
private static int Detokenize(Tuplet<ArrayDiffKind, Token>[] tokens, int index, XmlElement current, XmlDocument doc)
{
for(; index < tokens.Length; ++index) {
Tuplet<ArrayDiffKind, Token> token = tokens[index];
switch(token.Item1) {
case ArrayDiffKind.Same:
case ArrayDiffKind.Added:
switch(token.Item2.Type) {
case XmlNodeType.CDATA:
if(current == null) {
throw new ArgumentNullException("current");
}
current.AppendChild(doc.CreateCDataSection(token.Item2.Value));
break;
case XmlNodeType.Comment:
if(current == null) {
throw new ArgumentNullException("current");
}
current.AppendChild(doc.CreateComment(token.Item2.Value));
break;
case XmlNodeType.SignificantWhitespace:
if(current == null) {
throw new ArgumentNullException("current");
}
current.AppendChild(doc.CreateSignificantWhitespace(token.Item2.Value));
break;
case XmlNodeType.Text:
if(current == null) {
throw new ArgumentNullException("current");
}
current.AppendChild(doc.CreateTextNode(token.Item2.Value));
break;
case XmlNodeType.Whitespace:
if(current == null) {
throw new ArgumentNullException("current");
}
current.AppendChild(doc.CreateWhitespace(token.Item2.Value));
break;
case XmlNodeType.Element:
XmlElement next = doc.CreateElement(token.Item2.Value);
if(current == null) {
doc.AppendChild(next);
} else {
current.AppendChild(next);
}
index = Detokenize(tokens, index + 1, next, doc);
break;
case XmlNodeType.Attribute:
if(current == null) {
throw new ArgumentNullException("current");
}
string[] parts = token.Item2.Value.Split(new char[] { '=' }, 2);
current.SetAttribute(parts[0], parts[1]);
break;
case XmlNodeType.EndElement:
// nothing to do
break;
case XmlNodeType.None:
if(current == null) {
throw new ArgumentNullException("current");
}
// ensure we're closing the intended element
if(token.Item2.Value != current.Name) {
throw new InvalidOperationException(string.Format("mismatched element ending; found </{0}>, expected </{1}>", token.Item2.Value, current.Name));
}
// we're done with this sequence
return index;
default:
throw new InvalidOperationException("unhandled node type: " + token.Item2.Type);
}
break;
case ArrayDiffKind.Removed:
// ignore removed nodes
break;
default:
throw new InvalidOperationException("invalid diff kind: " + token.Item1);
}
}
if(current != null) {
throw new InvalidOperationException("unexpected end of tokens");
}
return index;
}
示例9: GetSnapshot
/**
* Reply to the http request
*/
public XmlDocument GetSnapshot(string regionName)
{
CheckStale();
XmlDocument requestedSnap = new XmlDocument();
requestedSnap.AppendChild(requestedSnap.CreateXmlDeclaration("1.0", null, null));
requestedSnap.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
XmlNode regiondata = requestedSnap.CreateNode(XmlNodeType.Element, "regiondata", "");
try
{
if (string.IsNullOrEmpty(regionName))
{
XmlNode timerblock = requestedSnap.CreateNode(XmlNodeType.Element, "expire", "");
timerblock.InnerText = m_period.ToString();
regiondata.AppendChild(timerblock);
regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
foreach (Scene scene in m_scenes)
{
regiondata.AppendChild(m_snapStore.GetScene(scene, requestedSnap));
}
}
else
{
Scene scene = SceneForName(regionName);
regiondata.AppendChild(m_snapStore.GetScene(scene, requestedSnap));
}
requestedSnap.AppendChild(regiondata);
regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
}
catch (XmlException e)
{
m_log.Warn("[DATASNAPSHOT]: XmlException while trying to load snapshot: " + e.ToString());
requestedSnap = GetErrorMessage(regionName, e);
}
catch (Exception e)
{
m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to load snapshot: " + e.StackTrace);
requestedSnap = GetErrorMessage(regionName, e);
}
return requestedSnap;
}
示例10: AsText_on_element_concats_whitespace_text_significant_whitespace_and_CDATA
public void AsText_on_element_concats_whitespace_text_significant_whitespace_and_CDATA()
{
var document = new XmlDocument();
document.AppendChild(document.CreateElement("test"));
var x = document.CreateElement("x");
document.DocumentElement.AppendChild(x);
x.AppendChild(document.CreateTextNode("foo"));
x.AppendChild(document.CreateWhitespace(" "));
x.AppendChild(document.CreateCDataSection("bar"));
x.AppendChild(document.CreateSignificantWhitespace(" "));
var doc = new XDoc(document);
Assert.AreEqual("foo bar ", doc["x"].AsText);
}
示例11: CreateAction
private void CreateAction()
{
XmlDocument document = new XmlDocument();
XmlNode node = document.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
document.AppendChild(node);
node = document.CreateComment($" Special Actions Configuration Data. {DateTime.Now} ");
document.AppendChild(node);
node = document.CreateWhitespace("\r\n");
document.AppendChild(node);
node = document.CreateNode(XmlNodeType.Element, "Actions", string.Empty);
document.AppendChild(node);
document.Save(m_Actions);
}
示例12: SetPropertyValue
private bool SetPropertyValue(XmlDocument xmlDoc, string PropertyName, string NewValue)
{
XmlNode parentNode = xmlDoc.DocumentElement.SelectSingleNode("appSettings");
if (parentNode == null)
{
parentNode = xmlDoc.CreateElement("appSettings");
xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n "));
xmlDoc.DocumentElement.AppendChild(parentNode);
xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n"));
}
return XmlHelper.SetPropertyValue(xmlDoc, PropertyName, NewValue, parentNode, "add", "key", "value");
}
示例13: AsText_on_whitespace_should_return_value
public void AsText_on_whitespace_should_return_value()
{
var document = new XmlDocument();
document.AppendChild(document.CreateElement("test"));
var x = document.CreateElement("x");
document.DocumentElement.AppendChild(x);
x.AppendChild(document.CreateWhitespace(" "));
var doc = new XDoc(document);
Assert.AreEqual(" ", doc["x"][0].AsText);
}
示例14: Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
Response.ExpiresAbsolute = new DateTime(1980, 1, 1, 0, 0, 0, 0);
Response.CacheControl = "no-cache";
XmlDocument xml = new XmlDocument();
xml.PreserveWhitespace = true;
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
xml.AppendChild(xml.CreateWhitespace("\n"));
XmlNode xConnector = xml.CreateElement("Connector");
xml.AppendChild(xConnector);
try
{
string sCommand = Sql.ToString(Request["Command" ]);
string sResourceType = Sql.ToString(Request["Type" ]);
string sCurrentFolder = Sql.ToString(Request["CurrentFolder"]);
if ( !Security.IsAuthenticated() )
{
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNodeAttribute(xml, "Error", "number", "1");
XmlUtil.SetSingleNodeAttribute(xml, "Error", "text" , "Authentication is required.");
xConnector.AppendChild(xml.CreateWhitespace("\n"));
}
else if ( Sql.IsEmptyString(sCommand) || Sql.IsEmptyString(sResourceType) || Sql.IsEmptyString(sCurrentFolder) )
{
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNodeAttribute(xml, "Error", "number", "1");
XmlUtil.SetSingleNodeAttribute(xml, "Error", "text" , "Invalid request.");
xConnector.AppendChild(xml.CreateWhitespace("\n"));
}
else
{
string sSiteURL = Utils.MassEmailerSiteURL(Context.Application);
string sFileURL = sSiteURL + "Images/EmailImage.aspx?ID=";
switch ( sCommand )
{
case "FileUpload":
{
int nErrorNumber = 0;
string sFileName = String.Empty;
string sCustomMsg = String.Empty;
Guid gImageID = Guid.Empty;
DbProviderFactory dbf = DbProviderFactories.GetFactory();
using ( IDbConnection con = dbf.CreateConnection() )
{
con.Open();
// 10/07/2009 We need to create our own global transaction ID to support auditing and workflow on SQL Azure, PostgreSQL, Oracle, DB2 and MySQL.
using ( IDbTransaction trn = Sql.BeginTransaction(con) )
{
try
{
FileWorkerUtils.LoadImage(ref gImageID, ref sFileName, trn);
if ( Sql.IsEmptyGuid(gImageID) )
nErrorNumber = 202;
else
sFileURL += gImageID.ToString();
trn.Commit();
}
catch
{
trn.Rollback();
throw;
}
}
}
Response.Write("<script type=\"text/javascript\">\n");
Response.Write("window.parent.frames['frmUpload'].OnUploadCompleted(" + nErrorNumber.ToString() + ",'" + Sql.EscapeJavaScript(sFileURL) + "','" + Sql.EscapeJavaScript(sFileName) + "','" + Sql.EscapeJavaScript(sCustomMsg) + "');\n");
Response.Write("</script>\n");
return;
}
case "GetFolders":
{
XmlUtil.SetSingleNodeAttribute(xml, xConnector, "command" , sCommand );
XmlUtil.SetSingleNodeAttribute(xml, xConnector, "resourceType", sResourceType);
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "path" , sCurrentFolder);
XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "url" , sFileURL );
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNode (xml, "Folders" , "");
xConnector.AppendChild(xml.CreateWhitespace("\n"));
break;
}
case "GetFoldersAndFiles":
{
XmlUtil.SetSingleNodeAttribute(xml, xConnector, "command" , sCommand );
XmlUtil.SetSingleNodeAttribute(xml, xConnector, "resourceType", sResourceType);
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "path" , sCurrentFolder);
XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "url" , sFileURL );
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
XmlUtil.SetSingleNode (xml, "Folders" , "");
xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
//.........这里部分代码省略.........
示例15: AddNewLine
private void AddNewLine(XmlDocument document, XmlElement targetElement)
{
targetElement.AppendChild(document.CreateWhitespace("\n"));
}