本文整理汇总了C#中System.Configuration.XmlUtilWriter.AppendCData方法的典型用法代码示例。如果您正苦于以下问题:C# XmlUtilWriter.AppendCData方法的具体用法?C# XmlUtilWriter.AppendCData怎么用?C# XmlUtilWriter.AppendCData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.XmlUtilWriter
的用法示例。
在下文中一共展示了XmlUtilWriter.AppendCData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyXmlNode
//.........这里部分代码省略.........
charactersWritten += utilWriter.Write('=');
charactersWritten += utilWriter.AppendAttributeValue(_reader);
// Update position. Note that the attribute value is escaped to always be on a single line.
lineNumber = attrLineNumber;
linePosition = attrLinePosition + charactersWritten;
}
// Position reader at beginning of node
_reader.MoveToElement();
}
else if (nodeType == XmlNodeType.SignificantWhitespace) {
utilWriter.Write(_reader.Value);
}
else if (nodeType == XmlNodeType.ProcessingInstruction) {
//
// Note that there is no way to get spacing between attribute name and value
// For example:
//
// <?pi "value" ?>
//
// is reported with the same position as
//
// <?pi "value" ?>
//
// The first example has one space between 'pi' and "value", the second has multiple spaces.
//
utilWriter.AppendProcessingInstruction(_reader.Name, _reader.Value);
}
else if (nodeType == XmlNodeType.EntityReference) {
utilWriter.AppendEntityRef(_reader.Name);
}
else if (nodeType == XmlNodeType.CDATA) {
utilWriter.AppendCData(_reader.Value);
}
else if (nodeType == XmlNodeType.DocumentType) {
//
// XmlNodeType.DocumentType has the following format:
//
// <!DOCTYPE rootElementName {(SYSTEM uriRef)|(PUBLIC id uriRef)} {[ dtdDecls ]} >
//
// The reader only gives us the position of 'rootElementName', so we must track what was
// written before "<!DOCTYPE" in order to correctly determine the position of the
// <!DOCTYPE tag
//
Debug.Assert(utilWriter.TrackPosition, "utilWriter.TrackPosition");
int c = utilWriter.Write("<!DOCTYPE");
// Write the space between <!DOCTYPE and the rootElementName
utilWriter.AppendRequiredWhiteSpace(_lastLineNumber, _lastLinePosition + c, _reader.LineNumber, _reader.LinePosition);
// Write the rootElementName
utilWriter.Write(_reader.Name);
// Get the dtd declarations, if any
string dtdValue = null;
if (_reader.HasValue) {
dtdValue = _reader.Value;
}
// get line position after the !DOCTYPE declaration:
// <!DOCTYPE rootElement SYSTEM rootElementDtdUri >
// ^
// linePosition
lineNumber = _reader.LineNumber;
linePosition = _reader.LinePosition + _reader.Name.Length;
示例2: FormatXmlElement
internal static string FormatXmlElement(string xmlElement, int linePosition, int indent, bool skipFirstIndent)
{
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.Default, Encoding.Unicode);
XmlTextReader reader = new XmlTextReader(xmlElement, XmlNodeType.Element, context);
StringWriter writer = new StringWriter(new StringBuilder(0x40), CultureInfo.InvariantCulture);
XmlUtilWriter writer2 = new XmlUtilWriter(writer, false);
bool newLine = false;
bool flag2 = false;
int num2 = 0;
while (reader.Read())
{
int num;
int attributeCount;
int num4;
bool flag3;
XmlNodeType nodeType = reader.NodeType;
if (flag2)
{
writer2.Flush();
num = num2 - ((StringWriter) writer2.Writer).GetStringBuilder().Length;
}
else
{
num = 0;
}
XmlNodeType type2 = nodeType;
if (type2 <= XmlNodeType.CDATA)
{
switch (type2)
{
case XmlNodeType.Element:
case XmlNodeType.CDATA:
goto Label_0091;
}
goto Label_00CA;
}
if ((type2 != XmlNodeType.Comment) && (type2 != XmlNodeType.EndElement))
{
goto Label_00CA;
}
Label_0091:
if (!skipFirstIndent && !flag2)
{
writer2.AppendIndent(linePosition, indent, reader.Depth, newLine);
if (newLine)
{
writer2.Flush();
num2 = ((StringWriter) writer2.Writer).GetStringBuilder().Length;
}
}
Label_00CA:
flag2 = false;
switch (nodeType)
{
case XmlNodeType.Element:
writer2.Write('<');
writer2.Write(reader.Name);
num += reader.Name.Length + 2;
attributeCount = reader.AttributeCount;
num4 = 0;
goto Label_0274;
case XmlNodeType.Text:
writer2.AppendEscapeTextString(reader.Value);
flag2 = true;
goto Label_02D6;
case XmlNodeType.CDATA:
writer2.AppendCData(reader.Value);
goto Label_02D6;
case XmlNodeType.EntityReference:
writer2.AppendEntityRef(reader.Name);
goto Label_02D6;
case XmlNodeType.ProcessingInstruction:
writer2.AppendProcessingInstruction(reader.Name, reader.Value);
goto Label_02D6;
case XmlNodeType.Comment:
writer2.AppendComment(reader.Value);
goto Label_02D6;
case XmlNodeType.SignificantWhitespace:
writer2.Write(reader.Value);
goto Label_02D6;
case XmlNodeType.EndElement:
writer2.Write("</");
writer2.Write(reader.Name);
writer2.Write('>');
goto Label_02D6;
default:
goto Label_02D6;
}
Label_01BE:
if (num > 60)
{
writer2.AppendIndent(linePosition, indent, reader.Depth - 1, true);
//.........这里部分代码省略.........
示例3: FormatXmlElement
// Format an Xml element to be written to the config file.
// Params:
// xmlElement - the element
// linePosition - start position of the element
// indent - indent for each depth
// skipFirstIndent - skip indent for the first element?
//
static internal string FormatXmlElement(string xmlElement, int linePosition, int indent, bool skipFirstIndent) {
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.Default, Encoding.Unicode);
XmlTextReader reader = new XmlTextReader(xmlElement, XmlNodeType.Element, context);
StringWriter stringWriter = new StringWriter(new StringBuilder(64), CultureInfo.InvariantCulture);
XmlUtilWriter utilWriter = new XmlUtilWriter(stringWriter, false);
// append newline before indent?
bool newLine = false;
// last node visited was text?
bool lastWasText = false;
// width of line from end of indentation
int lineWidth;
// length of the stringbuilder after last indent with newline
int sbLengthLastNewLine = 0;
while (reader.Read()) {
XmlNodeType nodeType = reader.NodeType;
if (lastWasText) {
utilWriter.Flush();
lineWidth = sbLengthLastNewLine - ((StringWriter)utilWriter.Writer).GetStringBuilder().Length;
}
else {
lineWidth = 0;
}
switch (nodeType) {
case XmlNodeType.CDATA:
case XmlNodeType.Element:
case XmlNodeType.EndElement:
case XmlNodeType.Comment:
// Do not indent if the last node was text - doing so would add whitespace
// that is included as part of the text.
if (!skipFirstIndent && !lastWasText) {
utilWriter.AppendIndent(linePosition, indent, reader.Depth, newLine);
if (newLine) {
utilWriter.Flush();
sbLengthLastNewLine = ((StringWriter)utilWriter.Writer).GetStringBuilder().Length;
}
}
break;
default:
break;
}
lastWasText = false;
switch (nodeType) {
case XmlNodeType.Whitespace:
break;
case XmlNodeType.SignificantWhitespace:
utilWriter.Write(reader.Value);
break;
case XmlNodeType.CDATA:
utilWriter.AppendCData(reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
utilWriter.AppendProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.Comment:
utilWriter.AppendComment(reader.Value);
break;
case XmlNodeType.Text:
utilWriter.AppendEscapeTextString(reader.Value);
lastWasText = true;
break;
case XmlNodeType.Element:
{
// Write "<elem"
utilWriter.Write('<');
utilWriter.Write(reader.Name);
lineWidth += reader.Name.Length + 2;
int c = reader.AttributeCount;
for (int i = 0; i < c; i++) {
// Add new line if we've exceeded the line width
bool writeSpace;
if (lineWidth > MAX_LINE_WIDTH) {
utilWriter.AppendIndent(linePosition, indent, reader.Depth - 1, true);
lineWidth = indent;
//.........这里部分代码省略.........
示例4: CopyXmlNode
internal bool CopyXmlNode(XmlUtilWriter utilWriter)
{
string s = null;
int fromLineNumber = -1;
int fromLinePosition = -1;
int lineNumber = 0;
int linePosition = 0;
int num5 = 0;
int num6 = 0;
if (utilWriter.TrackPosition)
{
lineNumber = this._reader.LineNumber;
linePosition = this._reader.LinePosition;
num5 = utilWriter.LineNumber;
num6 = utilWriter.LinePosition;
}
XmlNodeType nodeType = this._reader.NodeType;
switch (nodeType)
{
case XmlNodeType.Whitespace:
utilWriter.Write(this._reader.Value);
break;
case XmlNodeType.Element:
s = this._reader.IsEmptyElement ? "/>" : ">";
fromLineNumber = this._reader.LineNumber;
fromLinePosition = this._reader.LinePosition + this._reader.Name.Length;
utilWriter.Write('<');
utilWriter.Write(this._reader.Name);
while (this._reader.MoveToNextAttribute())
{
int toLineNumber = this._reader.LineNumber;
int toLinePosition = this._reader.LinePosition;
utilWriter.AppendRequiredWhiteSpace(fromLineNumber, fromLinePosition, toLineNumber, toLinePosition);
int num9 = utilWriter.Write(this._reader.Name) + utilWriter.Write('=');
num9 += utilWriter.AppendAttributeValue(this._reader);
fromLineNumber = toLineNumber;
fromLinePosition = toLinePosition + num9;
}
break;
case XmlNodeType.EndElement:
s = ">";
fromLineNumber = this._reader.LineNumber;
fromLinePosition = this._reader.LinePosition + this._reader.Name.Length;
utilWriter.Write("</");
utilWriter.Write(this._reader.Name);
break;
case XmlNodeType.Comment:
utilWriter.AppendComment(this._reader.Value);
break;
case XmlNodeType.Text:
utilWriter.AppendEscapeTextString(this._reader.Value);
break;
case XmlNodeType.XmlDeclaration:
s = "?>";
fromLineNumber = this._reader.LineNumber;
fromLinePosition = this._reader.LinePosition + 3;
utilWriter.Write("<?xml");
while (this._reader.MoveToNextAttribute())
{
int num10 = this._reader.LineNumber;
int num11 = this._reader.LinePosition;
utilWriter.AppendRequiredWhiteSpace(fromLineNumber, fromLinePosition, num10, num11);
int num12 = utilWriter.Write(this._reader.Name) + utilWriter.Write('=');
num12 += utilWriter.AppendAttributeValue(this._reader);
fromLineNumber = num10;
fromLinePosition = num11 + num12;
}
this._reader.MoveToElement();
break;
case XmlNodeType.SignificantWhitespace:
utilWriter.Write(this._reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
utilWriter.AppendProcessingInstruction(this._reader.Name, this._reader.Value);
break;
case XmlNodeType.EntityReference:
utilWriter.AppendEntityRef(this._reader.Name);
break;
case XmlNodeType.CDATA:
utilWriter.AppendCData(this._reader.Value);
break;
default:
if (nodeType == XmlNodeType.DocumentType)
{
int num13 = utilWriter.Write("<!DOCTYPE");
utilWriter.AppendRequiredWhiteSpace(this._lastLineNumber, this._lastLinePosition + num13, this._reader.LineNumber, this._reader.LinePosition);
utilWriter.Write(this._reader.Name);
string str2 = null;
if (this._reader.HasValue)
{
//.........这里部分代码省略.........