本文整理汇总了C#中System.Xml.XmlWriter.WriteEntityRef方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteEntityRef方法的具体用法?C# XmlWriter.WriteEntityRef怎么用?C# XmlWriter.WriteEntityRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteEntityRef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteShallowNode
public static void WriteShallowNode(XmlReader reader, XmlWriter writer)
{
//Console.WriteLine("{0}: {1}", reader.NodeType, reader.Name);
switch(reader.NodeType) {
case XmlNodeType.Element:
writer.WriteStartElement(reader.Prefix , reader.LocalName, reader.NamespaceURI);
writer.WriteAttributes(reader, true);
if(reader.IsEmptyElement)
writer.WriteEndElement();
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteWhitespace(reader.Value);
break;
case XmlNodeType.CDATA:
writer.WriteCData(reader.Value);
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.DocumentType:
writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
break;
}
}
示例2: InvokeMethod
private void InvokeMethod(XmlWriter w, string methodName)
{
byte[] buffer = new byte[10];
switch (methodName)
{
case "WriteStartDocument":
w.WriteStartDocument();
break;
case "WriteStartElement":
w.WriteStartElement("root");
break;
case "WriteEndElement":
w.WriteEndElement();
break;
case "WriteStartAttribute":
w.WriteStartAttribute("attr");
break;
case "WriteEndAttribute":
w.WriteEndAttribute();
break;
case "WriteCData":
w.WriteCData("test");
break;
case "WriteComment":
w.WriteComment("test");
break;
case "WritePI":
w.WriteProcessingInstruction("name", "test");
break;
case "WriteEntityRef":
w.WriteEntityRef("e");
break;
case "WriteCharEntity":
w.WriteCharEntity('c');
break;
case "WriteSurrogateCharEntity":
w.WriteSurrogateCharEntity('\uDC00', '\uDBFF');
break;
case "WriteWhitespace":
w.WriteWhitespace(" ");
break;
case "WriteString":
w.WriteString("foo");
break;
case "WriteChars":
char[] charArray = new char[] { 'a', 'b', 'c', 'd' };
w.WriteChars(charArray, 0, 3);
break;
case "WriteRaw":
w.WriteRaw("<foo>bar</foo>");
break;
case "WriteBase64":
w.WriteBase64(buffer, 0, 9);
break;
case "WriteBinHex":
w.WriteBinHex(buffer, 0, 9);
break;
case "LookupPrefix":
string str = w.LookupPrefix("foo");
break;
case "WriteNmToken":
w.WriteNmToken("foo");
break;
case "WriteName":
w.WriteName("foo");
break;
case "WriteQualifiedName":
w.WriteQualifiedName("foo", "bar");
break;
case "WriteValue":
w.WriteValue(Int32.MaxValue);
break;
case "WriteAttributes":
XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>"));
xr1.Read();
w.WriteAttributes(xr1, false);
break;
case "WriteNodeReader":
XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>"));
xr2.Read();
w.WriteNode(xr2, false);
break;
case "Flush":
w.Flush();
break;
default:
CError.Equals(false, "Unexpected param in testcase: {0}", methodName);
break;
}
}
示例3: PassNodeThrough
//copies from example
private void PassNodeThrough(XmlReader reader, XmlWriter writer)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
writer.WriteAttributes(reader, true);
if (reader.IsEmptyElement)
{
writer.WriteEndElement();
}
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteWhitespace(reader.Value);
break;
case XmlNodeType.CDATA:
writer.WriteCData(reader.Value);
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.DocumentType:
writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
break;
}
}
示例4: WriteNodeAsync
// Writes the content (inner XML) of the current node into the provided XmlWriter.
private async Task WriteNodeAsync(XmlWriter xtw, bool defattr)
{
int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth;
while (await this.ReadAsync().ConfigureAwait(false) && (d < this.Depth))
{
switch (this.NodeType)
{
case XmlNodeType.Element:
xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
xtw.WriteAttributes(this, defattr);
if (this.IsEmptyElement)
{
xtw.WriteEndElement();
}
break;
case XmlNodeType.Text:
xtw.WriteString(await this.GetValueAsync().ConfigureAwait(false));
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
xtw.WriteWhitespace(await this.GetValueAsync().ConfigureAwait(false));
break;
case XmlNodeType.CDATA:
xtw.WriteCData(this.Value);
break;
case XmlNodeType.EntityReference:
xtw.WriteEntityRef(this.Name);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
xtw.WriteProcessingInstruction(this.Name, this.Value);
break;
case XmlNodeType.DocumentType:
xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
break;
case XmlNodeType.Comment:
xtw.WriteComment(this.Value);
break;
case XmlNodeType.EndElement:
xtw.WriteFullEndElement();
break;
}
}
if (d == this.Depth && this.NodeType == XmlNodeType.EndElement)
{
await ReadAsync().ConfigureAwait(false);
}
}
示例5: WriteNode
private void WriteNode(XmlWriter xtw, bool defattr)
{
int num = (this.NodeType == XmlNodeType.None) ? -1 : this.Depth;
while (this.Read() && (num < this.Depth))
{
switch (this.NodeType)
{
case XmlNodeType.Element:
xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
((XmlTextWriter) xtw).QuoteChar = this.QuoteChar;
xtw.WriteAttributes(this, defattr);
if (this.IsEmptyElement)
{
xtw.WriteEndElement();
}
break;
case XmlNodeType.Text:
xtw.WriteString(this.Value);
break;
case XmlNodeType.CDATA:
xtw.WriteCData(this.Value);
break;
case XmlNodeType.EntityReference:
xtw.WriteEntityRef(this.Name);
break;
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
xtw.WriteProcessingInstruction(this.Name, this.Value);
break;
case XmlNodeType.Comment:
xtw.WriteComment(this.Value);
break;
case XmlNodeType.DocumentType:
xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
xtw.WriteWhitespace(this.Value);
break;
case XmlNodeType.EndElement:
xtw.WriteFullEndElement();
break;
}
}
if ((num == this.Depth) && (this.NodeType == XmlNodeType.EndElement))
{
this.Read();
}
}
示例6: Preprocess
/// <summary>
/// Preprocesses and copies an Xml document from a reader into a writer.
/// </summary>
/// <param name="xmlReader">The Xml reader.</param>
/// <param name="xmlWriter">The Xml writer.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="xmlReader"/>
/// or <paramref name="xmlWriter"/> is null.</exception>
/// <exception cref="InvalidOperationException">Thrown if the input Xml is malformed
/// such as if it contains unbalanced ifdef/endif pairs.</exception>
public void Preprocess(XmlReader xmlReader, XmlWriter xmlWriter)
{
if (xmlReader == null)
throw new ArgumentNullException("xmlReader");
if (xmlWriter == null)
throw new ArgumentNullException("xmlWriter");
// Tracks whether a given block has been included or excluded.
Stack<bool> blockStack = new Stack<bool>();
blockStack.Push(true);
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.ProcessingInstruction)
{
switch (xmlReader.Name)
{
case "define":
if (blockStack.Peek())
Define(xmlReader.Value.Trim());
continue;
case "ifdef":
blockStack.Push(blockStack.Peek() && IsDefined(xmlReader.Value.Trim()));
continue;
case "ifndef":
blockStack.Push(blockStack.Peek() && !IsDefined(xmlReader.Value.Trim()));
continue;
case "else":
if (blockStack.Count == 1)
throw new InvalidOperationException(
"Found <?else?> instruction without enclosing <?ifdef?> or <?ifndef?> block.");
blockStack.Push(!blockStack.Pop() && blockStack.Peek()); // order matters
continue;
case "endif":
if (blockStack.Count == 1)
throw new InvalidOperationException(
"Found <?endif?> instruction without matching <?ifdef?> or <?ifndef?>.");
blockStack.Pop();
continue;
}
}
if (!blockStack.Peek())
continue;
switch (xmlReader.NodeType)
{
case XmlNodeType.Element:
xmlWriter.WriteStartElement(xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
xmlWriter.WriteAttributes(xmlReader, true);
if (xmlReader.IsEmptyElement)
xmlWriter.WriteEndElement();
break;
case XmlNodeType.Text:
xmlWriter.WriteValue(xmlReader.Value);
break;
case XmlNodeType.CDATA:
xmlWriter.WriteCData(xmlReader.Value);
break;
case XmlNodeType.EntityReference:
xmlWriter.WriteEntityRef(xmlReader.Name);
break;
case XmlNodeType.Comment:
xmlWriter.WriteComment(xmlReader.Value);
break;
case XmlNodeType.DocumentType:
xmlWriter.WriteDocType(xmlReader.Name, xmlReader.GetAttribute("PUBLIC"),
xmlReader.GetAttribute("SYSTEM"), xmlReader.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
xmlWriter.WriteWhitespace(xmlReader.Value);
break;
case XmlNodeType.EndElement:
xmlWriter.WriteFullEndElement();
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
xmlWriter.WriteProcessingInstruction(xmlReader.Name, xmlReader.Value);
//.........这里部分代码省略.........
示例7: WriteTopic
/// <summary>
/// This is used to write out the body content of a topic to the main document part
/// </summary>
/// <param name="writer">The writer for the main document part</param>
/// <param name="reader">The reader for the topic body content</param>
/// <remarks>Using a reader prevents unnecessary namespaces from appearing on the body content elements
/// which happens if we convert the XElement content to a string and write it out as raw content.</remarks>
private static void WriteTopic(XmlWriter writer, XmlReader reader)
{
while(!reader.EOF)
{
reader.Read();
switch(reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
writer.WriteAttributes(reader, true);
if(reader.IsEmptyElement)
writer.WriteEndElement();
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteWhitespace(reader.Value);
break;
case XmlNodeType.CDATA:
writer.WriteCData(reader.Value);
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EndElement:
// Stop when the end of the body is reached
if(reader.LocalName == "body")
return;
writer.WriteFullEndElement();
break;
}
}
}
示例8: EventsToWriter
/// <summary>
/// Replay all cached events to an XmlWriter.
/// </summary>
public void EventsToWriter(XmlWriter writer) {
XmlEvent[] page;
int idxPage, idxEvent;
byte[] bytes;
char[] chars;
XmlRawWriter rawWriter;
// Special-case single text node at the top-level
if (this.singleText.Count != 0) {
writer.WriteString(this.singleText.GetResult());
return;
}
rawWriter = writer as XmlRawWriter;
// Loop over set of pages
for (idxPage = 0; idxPage < this.pages.Count; idxPage++) {
page = this.pages[idxPage];
// Loop over events in each page
for (idxEvent = 0; idxEvent < page.Length; idxEvent++) {
switch (page[idxEvent].EventType) {
case XmlEventType.Unknown:
// No more events
Debug.Assert(idxPage + 1 == this.pages.Count);
return;
case XmlEventType.DocType:
writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string) page[idxEvent].Object);
break;
case XmlEventType.StartElem:
writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
break;
case XmlEventType.StartAttr:
writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
break;
case XmlEventType.EndAttr:
writer.WriteEndAttribute();
break;
case XmlEventType.CData:
writer.WriteCData(page[idxEvent].String1);
break;
case XmlEventType.Comment:
writer.WriteComment(page[idxEvent].String1);
break;
case XmlEventType.PI:
writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
break;
case XmlEventType.Whitespace:
writer.WriteWhitespace(page[idxEvent].String1);
break;
case XmlEventType.String:
writer.WriteString(page[idxEvent].String1);
break;
case XmlEventType.Raw:
writer.WriteRaw(page[idxEvent].String1);
break;
case XmlEventType.EntRef:
writer.WriteEntityRef(page[idxEvent].String1);
break;
case XmlEventType.CharEnt:
writer.WriteCharEntity((char) page[idxEvent].Object);
break;
case XmlEventType.SurrCharEnt:
chars = (char[]) page[idxEvent].Object;
writer.WriteSurrogateCharEntity(chars[0], chars[1]);
break;
case XmlEventType.Base64:
bytes = (byte[]) page[idxEvent].Object;
writer.WriteBase64(bytes, 0, bytes.Length);
break;
case XmlEventType.BinHex:
bytes = (byte[]) page[idxEvent].Object;
writer.WriteBinHex(bytes, 0, bytes.Length);
break;
case XmlEventType.XmlDecl1:
if (rawWriter != null)
rawWriter.WriteXmlDeclaration((XmlStandalone) page[idxEvent].Object);
break;
case XmlEventType.XmlDecl2:
if (rawWriter != null)
//.........这里部分代码省略.........
示例9: LimitHtmlOnWordBoundary
private static void LimitHtmlOnWordBoundary(XmlWriter writer, XmlReader reader, int maxLength, out bool shouldWriteEllipses)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
int elementCount = 0;
int currentLength = 0;
shouldWriteEllipses = false;
int magicMinimumLength = Math.Min(5, (maxLength + 1) / 2);
int num = (reader.NodeType == XmlNodeType.None) ? -1 : reader.Depth;
do
{
bool done = false;
switch (reader.NodeType)
{
case XmlNodeType.Element:
elementCount++;
writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
writer.WriteAttributes(reader, false);
if (reader.IsEmptyElement)
{
elementCount--;
writer.WriteEndElement();
}
break;
case XmlNodeType.Text:
string value = reader.Value;
int strLen = value.Length;
if (currentLength + strLen > maxLength)
{
string almost = value.Substring(0, maxLength - currentLength + 1);
int lastSpace = almost.LastIndexOf(' ');
if (lastSpace < 0)
{
if (currentLength < magicMinimumLength)
{
value = value.Substring(0, maxLength - currentLength);
}
else
{
value = null;
}
}
else if (lastSpace + currentLength < magicMinimumLength)
{
value = value.Substring(0, maxLength - currentLength);
}
else
{
value = value.Substring(0, lastSpace);
}
shouldWriteEllipses = true;
done = true;
}
if (value != null)
{
writer.WriteString(value);
currentLength += value.Length;
}
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteString(reader.Value);
currentLength += reader.Value.Length;
break;
case XmlNodeType.EndElement:
elementCount--;
writer.WriteFullEndElement();
break;
case XmlNodeType.CDATA:
//writer.WriteCData(reader.Value);
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
currentLength++;
break;
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
//writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.Comment:
//writer.WriteComment(reader.Value);
break;
//.........这里部分代码省略.........
示例10: Slurp
static void Slurp(XmlWriter writer, string path, bool topLevel)
{
using (var stream = File.OpenRead(path))
{
var workingDirectory = Path.GetDirectoryName(path);
var reader = XmlReader.Create(stream);
if (topLevel)
{
writer.WriteStartDocument();
}
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
var writeEnd = reader.IsEmptyElement;
var wroteStart = false;
var node = new { reader.Prefix, reader.LocalName, reader.NamespaceURI };
if (reader.MoveToFirstAttribute())
{
do
{
var info = reader.SchemaInfo;
if (!reader.IsDefault && ((info == null) || !info.IsDefault))
{
if (reader.LocalName == "configSource")
{
Slurp(writer, GetIncludePath(workingDirectory, reader.Value), false);
writeEnd = false;
continue;
}
if (!wroteStart)
{
writer.WriteStartElement(node.Prefix, node.LocalName, node.NamespaceURI);
wroteStart = true;
}
writer.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
while (reader.ReadAttributeValue())
{
if (reader.NodeType == XmlNodeType.EntityReference)
{
writer.WriteEntityRef(reader.Name);
}
else
{
writer.WriteString(reader.Value);
}
}
writer.WriteEndAttribute();
}
}
while (reader.MoveToNextAttribute());
}
else
{
writer.WriteStartElement(node.Prefix, node.LocalName, node.NamespaceURI);
}
if (writeEnd)
{
writer.WriteEndElement();
}
break;
case XmlNodeType.Text:
writer.WriteValue(reader.Value);
break;
case XmlNodeType.Whitespace:
/*
if (reader.Depth > 0)
{
writer.WriteValue(reader.Value);
}
*/
break;
case XmlNodeType.EndElement:
writer.WriteEndElement();
break;
case XmlNodeType.CDATA:
writer.WriteCData(reader.Value);
break;
case XmlNodeType.XmlDeclaration:
break;
default:
throw new NotSupportedException();
}
}
}
}
示例11: WriteTo
public override void WriteTo(XmlWriter writer)
{
writer.WriteEntityRef(this.Value);
}
示例12: TransformXml
//.........这里部分代码省略.........
}
else
{
if (sopDepth >= 0 && reader.Depth == sopDepth + 1)
{
if (reader.Name == "CreatorID")
{
reader.Read();
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Guid" || reader.Name == "UUID")
{
reader.Read();
if (reader.NodeType == XmlNodeType.Text)
{
UUID uuid = UUID.Zero;
UUID.TryParse(reader.Value, out uuid);
creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid);
writer.WriteElementString("UUID", reader.Value);
reader.Read();
}
else
{
// If we unexpected run across mixed content in this node, still carry on
// transforming the subtree (this replicates earlier behaviour).
TransformXml(reader, writer);
}
}
else
{
// If we unexpected run across mixed content in this node, still carry on
// transforming the subtree (this replicates earlier behaviour).
TransformXml(reader, writer);
}
}
else if (reader.Name == "CreatorData")
{
reader.Read();
if (reader.NodeType == XmlNodeType.Text)
{
hasCreatorData = true;
writer.WriteString(reader.Value);
}
else
{
// If we unexpected run across mixed content in this node, still carry on
// transforming the subtree (this replicates earlier behaviour).
TransformXml(reader, writer);
}
}
}
}
if (reader.IsEmptyElement)
{
// m_log.DebugFormat("[HG ASSET MAPPER]: Writing end for empty element {0}", reader.Name);
writer.WriteEndElement();
}
break;
case XmlNodeType.EndElement:
// m_log.DebugFormat("Depth {0} at EndElement", reader.Depth);
if (sopDepth == reader.Depth)
{
if (!hasCreatorData && creator != null)
writer.WriteElementString(reader.Prefix, "CreatorData", reader.NamespaceURI, string.Format("{0};{1} {2}", m_HomeURI, creator.FirstName, creator.LastName));
// m_log.DebugFormat("[HG ASSET MAPPER]: Reset sopDepth");
sopDepth = -1;
creator = null;
hasCreatorData = false;
}
writer.WriteEndElement();
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.Name, reader.Value);
break;
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.XmlDeclaration:
// For various reasons, not all serializations have xml declarations (or consistent ones)
// and as it's embedded inside a byte stream we don't need it anyway, so ignore.
break;
default:
m_log.WarnFormat(
"[HG ASSET MAPPER]: Unrecognized node {0} in asset XML transform in {1}",
reader.NodeType, m_scene.Name);
break;
}
}
}
示例13: Replay
internal void Replay(XmlWriter writer)
{
if (this.singleStringValue != null)
{
writer.WriteString(this.singleStringValue);
}
else
{
for (int i = this.firstItem; i <= this.lastItem; i++)
{
BufferChunk chunk;
Item item = this.items[i];
switch (item.type)
{
case ItemType.EntityRef:
writer.WriteEntityRef((string) item.data);
break;
case ItemType.CharEntity:
writer.WriteCharEntity((char) item.data);
break;
case ItemType.SurrogateCharEntity:
{
char[] data = (char[]) item.data;
writer.WriteSurrogateCharEntity(data[0], data[1]);
break;
}
case ItemType.Whitespace:
writer.WriteWhitespace((string) item.data);
break;
case ItemType.String:
writer.WriteString((string) item.data);
break;
case ItemType.StringChars:
chunk = (BufferChunk) item.data;
writer.WriteChars(chunk.buffer, chunk.index, chunk.count);
break;
case ItemType.Raw:
writer.WriteRaw((string) item.data);
break;
case ItemType.RawChars:
chunk = (BufferChunk) item.data;
writer.WriteChars(chunk.buffer, chunk.index, chunk.count);
break;
case ItemType.ValueString:
writer.WriteValue((string) item.data);
break;
}
}
}
}
示例14: WriteNode
// Writes the content (inner XML) of the current node into the provided XmlWriter.
private void WriteNode(XmlWriter xtw, bool defattr) {
#if !SILVERLIGHT
Debug.Assert(xtw is XmlTextWriter);
#endif
int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth;
while (this.Read() && (d < this.Depth)) {
switch (this.NodeType) {
case XmlNodeType.Element:
xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
#if !SILVERLIGHT // Removing dependency on XmlTextWriter
((XmlTextWriter)xtw).QuoteChar = this.QuoteChar;
#endif
xtw.WriteAttributes(this, defattr);
if (this.IsEmptyElement) {
xtw.WriteEndElement();
}
break;
case XmlNodeType.Text:
xtw.WriteString(this.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
xtw.WriteWhitespace(this.Value);
break;
case XmlNodeType.CDATA:
xtw.WriteCData(this.Value);
break;
case XmlNodeType.EntityReference:
xtw.WriteEntityRef(this.Name);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
xtw.WriteProcessingInstruction(this.Name, this.Value);
break;
case XmlNodeType.DocumentType:
xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
break;
case XmlNodeType.Comment:
xtw.WriteComment(this.Value);
break;
case XmlNodeType.EndElement:
xtw.WriteFullEndElement();
break;
}
}
if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) {
Read();
}
}
示例15: WriteShallowNode
// From http://blogs.msdn.com/b/mfussell/archive/2005/02/12/371546.aspx
static void WriteShallowNode( XmlReader reader, XmlWriter writer )
{
if ( reader == null )
{
throw new ArgumentNullException("reader");
}
if ( writer == null )
{
throw new ArgumentNullException("writer");
}
switch ( reader.NodeType )
{
case XmlNodeType.Element:
writer.WriteStartElement( reader.Prefix, reader.LocalName, reader.NamespaceURI );
writer.WriteAttributes( reader, true );
if ( reader.IsEmptyElement )
{
writer.WriteEndElement();
}
break;
case XmlNodeType.Text:
writer.WriteString( reader.Value );
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteWhitespace(reader.Value);
break;
case XmlNodeType.CDATA:
writer.WriteCData( reader.Value );
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction( reader.Name, reader.Value );
break;
case XmlNodeType.DocumentType:
writer.WriteDocType( reader.Name, reader.GetAttribute( "PUBLIC" ), reader.GetAttribute( "SYSTEM" ), reader.Value );
break;
case XmlNodeType.Comment:
writer.WriteComment( reader.Value );
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
break;
}
}