本文整理汇总了C#中XmlDocument.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Normalize方法的具体用法?C# XmlDocument.Normalize怎么用?C# XmlDocument.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.Normalize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args)
{
XmlValidatingReader reader =
new XmlValidatingReader(new XmlTextReader(args[0]));
if (args[1] == "false")
reader.ValidationType = ValidationType.None;
else {
reader.ValidationType = ValidationType.Schema;
reader.ValidationEventHandler +=
new ValidationEventHandler (ValidationHandler);
}
XmlDocument doc = new XmlDocument();
doc.Load(reader);
doc.Normalize();
XmlElement root = doc.DocumentElement;
XmlNodeList titles = root.GetElementsByTagName("title");
for (int i=0; i < titles.Count; i++) {
XmlNode title = titles[i];
XmlAttribute fullAt = title.Attributes["full"];
String full;
if (fullAt == null)
full = "true";
else
full = fullAt.Value;
XmlNode text = title.FirstChild;
String result = (full=="false") ? "is not" : "is";
Console.WriteLine("{0} {1} the full title.",
text.OuterXml, result);
}
}
示例2: EmptyWork
public static void EmptyWork()
{
var xml = "<root>\r\n text node one\r\n <elem1 child1=\"\" child2=\"duu\" child3=\"e1;e2;\" child4=\"a1\" child5=\"goody\">\r\n text node two e1; text node three\r\n </elem1><!-- comment3 --><?PI3 processing instruction?>e2;<foo /><![CDATA[ <opentag> without an </endtag> and & <! are all ok here ]]><elem2 att1=\"id1\" att2=\"up\" att3=\"attribute3\"><a /></elem2><elem2> \r\n elem2-text1\r\n <a> \r\n this-is-a \r\n </a> \r\n\r\n elem2-text2\r\n e3;e4;<!-- elem2-comment1-->\r\n elem2-text3\r\n\r\n <b> \r\n this-is-b\r\n </b>\r\n\r\n elem2-text4\r\n <?elem2_PI elem2-PI?>\r\n elem2-text5\r\n\r\n </elem2></root>";
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml);
xmlDocument.Normalize();
Assert.Equal(StripWhiteSpace(xml), StripWhiteSpace(xmlDocument.OuterXml));
}
示例3: NormalWork
public static void NormalWork()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<doc><elem1>hello</elem1></doc>");
var text = xmlDocument.CreateTextNode("Test_test");
xmlDocument.DocumentElement.FirstChild.AppendChild(text);
xmlDocument.Normalize();
Assert.Equal(1, xmlDocument.DocumentElement.FirstChild.ChildNodes.Count);
}
示例4: EmptyDocument
public static void EmptyDocument()
{
var xmlDocument = new XmlDocument();
xmlDocument.Normalize();
Assert.Equal(String.Empty, xmlDocument.OuterXml);
}
示例5: Main
//.........这里部分代码省略.........
XmlElement basetemplate = stylesheet.CreateElement("xsl:template", "http://www.w3.org/1999/XSL/Transform");
basetemplate.SetAttribute("match", "*");
basetemplate.InnerXml = "[<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select=\"name()\"/>:"
+ "<xsl:for-each select='*' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
+ "[<xsl:value-of select='name(.)'/>]"
+ "</xsl:for-each>]";
stylesheet_root.AppendChild(basetemplate);
StreamReader csgen = new StreamReader("csgen.txt");
System.Text.RegularExpressions.Regex SubstParam = new System.Text.RegularExpressions.Regex(@"@([\w\*]+)(\[[^\]]+\])?");
string csgen_line;
while ((csgen_line = csgen.ReadLine()) != null) {
if (csgen_line == "" || csgen_line[0] == '#') { continue; }
int sp = csgen_line.IndexOf(" ");
if (sp == -1) { continue; }
string rule = csgen_line.Substring(sp+1);
int priority = -1;
if (csgen_line.StartsWith("*"))
priority = 10;
if (csgen_line.StartsWith("!")) {
priority = 20;
csgen_line = csgen_line.Substring(1);
}
XmlElement template = stylesheet.CreateElement("xsl:template", "http://www.w3.org/1999/XSL/Transform");
template.SetAttribute("match", csgen_line.Substring(0, sp));
template.SetAttribute("xml:space", "preserve");
if (priority != -1)
template.SetAttribute("priority", priority.ToString());
if (rule == "none") {
template.InnerXml = "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='*'/>";
} else if (rule == "text") {
template.InnerXml = "<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='@Text'/>";
} else {
rule = rule.Replace("|", "\n");
if (!rule.EndsWith("\\")) rule += "\n"; else rule = rule.Substring(0, rule.Length-1);
rule = rule.Replace("@@1", "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='*[position()>1]'/>");
rule = rule.Replace("@@", "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform'/>");
foreach (System.Text.RegularExpressions.Match match in SubstParam.Matches(rule)) {
string type = match.Result("$1");
string sep = match.Result("$2");
if (sep != "") sep = sep.Substring(1, sep.Length-2);
if (type == "text") {
rule = rule.Replace(match.Value, "<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='@Text'/>");
} else {
if (char.IsDigit(type[0]))
type = "*[position()=" + type + "]";
if (sep == "")
rule = rule.Replace(match.Value, "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='" + type + "'/>");
else
rule = rule.Replace(match.Value,
"<xsl:for-each xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='" + type + "'>"
+ "<xsl:if test='not(position()=1)'>" + sep + "</xsl:if>"
+ "<xsl:apply-templates select='.'/>"
+ "</xsl:for-each>");
}
}
template.InnerXml = rule;
}
stylesheet_root.AppendChild(template);
}
CSharpAST
left = GetAST(args[0]),
right = GetAST(args[1]);
StringWriter buffer = new StringWriter();
XmlTextWriter output = new XmlTextWriter(buffer);
//output.Formatting = Formatting.Indented;
StructuredDiff test = new XmlOutputStructuredDiff(output, null);
test.AddInterface(typeof(ASTNode), new ASTNodeInterface());
test.Compare(left, right);
output.Close();
XmlDocument diff = new XmlDocument();
diff.LoadXml(buffer.ToString());
XslTransform transform = new XslTransform();
transform.Load(stylesheet);
XmlReader diffcontent = transform.Transform(diff, null);
throw new Exception(diffcontent.BaseURI == null ? "null" : "not null");
XmlDocument diffdoc = new XmlDocument();
diffdoc.Load(diffcontent);
diffdoc.Normalize();
WriteChildren(diffdoc.DocumentElement, 0, ' ');
Console.WriteLine();
}
示例6: GetLogData
private XmlDocument GetLogData(string url, string revision, string username, string password)
{
Cache cache = HttpRuntime.Cache;
string cacheKey = "LogData-" + revision + "-" + url;
if (cache[cacheKey] != null)
{
//return (XmlDocument) cache[cacheKey];
}
// svn log --xml -r [Revision] --non-interactive --limit [Limit] http://svn.website.com/svn/trunk
Process proc = new Process();
proc.StartInfo.FileName = "svn";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = "log --xml " +
GetRevisionArguments(revision, false) +
GetAuthArguments(username, password) +
" --non-interactive --limit " + FeedLimit + " " + url;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.WaitForExit(WaitDelay);
XmlDocument document = new XmlDocument();
document.Load(proc.StandardOutput);
document.Normalize();
cache.Insert(cacheKey, document, null, DateTime.Now.AddMinutes(5),
Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
return document;
}