本文整理汇总了C#中System.Xml.XmlDocument.CreateSignificantWhitespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateSignificantWhitespace方法的具体用法?C# XmlDocument.CreateSignificantWhitespace怎么用?C# XmlDocument.CreateSignificantWhitespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateSignificantWhitespace方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetReady
public void GetReady ()
{
document = new XmlDocument ();
document.LoadXml ("<root><foo></foo></root>");
XmlElement element = document.CreateElement ("foo");
whitespace = document.CreateSignificantWhitespace ("\r\n");
element.AppendChild (whitespace);
doc2 = new XmlDocument ();
}
示例2: ImportSignificantWhitespace
public static void ImportSignificantWhitespace()
{
var whitespace = " \t";
var tempDoc = new XmlDocument();
var nodeToImport = tempDoc.CreateSignificantWhitespace(whitespace);
var xmlDocument = new XmlDocument();
var node = xmlDocument.ImportNode(nodeToImport, true);
Assert.Equal(xmlDocument, node.OwnerDocument);
Assert.Equal(XmlNodeType.SignificantWhitespace, node.NodeType);
Assert.Equal(whitespace, node.Value);
}
示例3: 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 + "'");
}
}
示例4: SignificantWhitespaceIgnored2
public void SignificantWhitespaceIgnored2 ()
{
// To make sure, create pure significant whitespace element
// using XmlNodeReader (that does not have xml:space attribute
// column).
DataSet ds = new DataSet ();
XmlDocument doc = new XmlDocument ();
doc.AppendChild (doc.CreateElement ("root"));
doc.DocumentElement.AppendChild (doc.CreateSignificantWhitespace
(" \n\n"));
XmlReader xr = new XmlNodeReader (doc);
ds.InferXmlSchema (xr, null);
AssertDataSet ("pure_whitespace", ds, "root", 0, 0);
}
示例5: 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:
//.........这里部分代码省略.........
示例6: 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;
}
示例7: 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);
}
示例8: AsText_on_significant_whitespace_should_return_value
public void AsText_on_significant_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.CreateSignificantWhitespace(" "));
var doc = new XDoc(document);
Assert.AreEqual(" ", doc["x"][0].AsText);
}
示例9: CopyNode
void CopyNode (XmlDocument newDoc, XmlNode from, XmlNode toParent) {
if (RemoveAll && from.NodeType != XmlNodeType.Element)
return;
XmlNode child = null;
bool newLineNode = false;
switch (from.NodeType) {
case XmlNodeType.Element:
newLineNode = true;
if (RemoveNamespacesAndPrefixes)
child = newDoc.CreateElement (from.LocalName);
else {
XmlElement e = from as XmlElement;
child = newDoc.CreateElement (e.Prefix, e.LocalName, e.NamespaceURI);
}
break;
case XmlNodeType.Attribute: {
if (RemoveAttributes)
return;
XmlAttribute fromAttr = from as XmlAttribute;
if (!fromAttr.Specified)
return;
XmlAttribute a;
if (RemoveNamespacesAndPrefixes)
a = newDoc.CreateAttribute (fromAttr.LocalName);
else
a = newDoc.CreateAttribute (fromAttr.Prefix, fromAttr.LocalName, fromAttr.NamespaceURI);
toParent.Attributes.Append(a);
CopyNodes (newDoc, from, a);
return;
}
case XmlNodeType.CDATA:
newLineNode = true;
child = newDoc.CreateCDataSection ((from as XmlCDataSection).Data);
break;
case XmlNodeType.Comment:
if (RemoveWhiteSpace)
return;
newLineNode = true;
child = newDoc.CreateComment ((from as XmlComment).Data);
break;
case XmlNodeType.ProcessingInstruction:
newLineNode = true;
XmlProcessingInstruction pi = from as XmlProcessingInstruction;
child = newDoc.CreateProcessingInstruction (pi.Target, pi.Data);
break;
case XmlNodeType.DocumentType:
newLineNode = true;
toParent.AppendChild (from.CloneNode (true));
return;
case XmlNodeType.EntityReference:
child = newDoc.CreateEntityReference ((from as XmlEntityReference).Name);
break;
case XmlNodeType.SignificantWhitespace:
if (RemoveWhiteSpace)
return;
child = newDoc.CreateSignificantWhitespace (from.Value);
break;
case XmlNodeType.Text:
if (RemoveText)
return;
newLineNode = true;
child = newDoc.CreateTextNode (from.Value);
break;
case XmlNodeType.Whitespace:
if (RemoveWhiteSpace)
return;
child = newDoc.CreateWhitespace (from.Value);
break;
case XmlNodeType.XmlDeclaration:
newLineNode = true;
XmlDeclaration d = from as XmlDeclaration;
XmlDeclaration d1 = newDoc.CreateXmlDeclaration (d.Version, d.Encoding, d.Standalone);
newDoc.InsertBefore(d1, newDoc.DocumentElement);
return;
}
if (NewLines && newLineNode && toParent.NodeType != XmlNodeType.Attribute) {
XmlSignificantWhitespace s = newDoc.CreateSignificantWhitespace("\r\n");
toParent.AppendChild (s);
}
toParent.AppendChild(child);
CopyNodes (newDoc, from, child);
}
示例10: UpdateDirTree
public bool UpdateDirTree()
{
if (!GetAllDirNames())
{
return false;
}
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
doc.AppendChild(doc.CreateSignificantWhitespace("\r\n"));
XmlElement ele = doc.CreateElement("Root");
doc.AppendChild(ele);
XmlElement ele2 = doc.CreateElement("1");
XmlElement ele3 = doc.CreateElement("2");
ele.AppendChild(ele2);
ele.AppendChild(ele3);
if (AddChildNode(ref doc, ref ele2))
{
m_dirProvider.Document = doc;
return true;
}
else
{
return false;
}
}