格式化XML:输出有缩进效果的XML字符串
1. 一般情况下使用以下代码即可将XML字符串重新格式化:
private string FormatXml(string source)
{
StringBuilder sb = new StringBuilder();
XmlTextWriter writer = null;
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(source);
writer = new XmlTextWriter(new StringWriter(sb));
writer.Formatting = Formatting.Indented;
doc.WriteTo(writer);
}
finally
{
if (writer != null) writer.Close();
}
 
相关文档:
声明
/// <summary>
/// XML文档
/// </summary>
XmlDocument xmldoc;
&n ......
大量SmipleXML函数可用来加载和解析大量XML文档。
1.simpleXML_load_file()函数来加载指定的XML文件到对象。如果加载文件时遇到问题,则返回FLASE。例:
book.xml文件:
<?xml version="1.0" standalone="yes"?>
<library>
<book>
<title>Pride and Prejudice</title>
< ......
<?
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the ......
在java应用开发中我们和xml打交道得机会太平凡了,一般情况下我看会用JDOM或是DOM4j来解析我们得XML文件,下面是一个Dom4j解析xml文件得例子,其中包括了对xml文件得取值、赋值、提取节点、节点得遍历等。
SAXReader reader =
new
SAXReader();
Document doc = reader.read(...); &nb ......