本文整理汇总了C#中System.Xml.XmlWriter.WriteChars方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteChars方法的具体用法?C# XmlWriter.WriteChars怎么用?C# XmlWriter.WriteChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteChars方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Replay
internal void Replay(XmlWriter writer)
{
if (_singleStringValue != null)
{
writer.WriteString(_singleStringValue);
return;
}
BufferChunk bufChunk;
for (int i = _firstItem; i <= _lastItem; i++)
{
Item item = _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[] chars = (char[])item.data;
writer.WriteSurrogateCharEntity(chars[0], chars[1]);
break;
case ItemType.Whitespace:
writer.WriteWhitespace((string)item.data);
break;
case ItemType.String:
writer.WriteString((string)item.data);
break;
case ItemType.StringChars:
bufChunk = (BufferChunk)item.data;
writer.WriteChars(bufChunk.buffer, bufChunk.index, bufChunk.count);
break;
case ItemType.Raw:
writer.WriteRaw((string)item.data);
break;
case ItemType.RawChars:
bufChunk = (BufferChunk)item.data;
writer.WriteChars(bufChunk.buffer, bufChunk.index, bufChunk.count);
break;
case ItemType.ValueString:
writer.WriteValue((string)item.data);
break;
default:
Debug.Fail("Unexpected ItemType value.");
break;
}
}
}
示例2: WriteXamlTextSegment
//.........这里部分代码省略.........
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
}
else if (nextElement != null)
{
//
TextElementEditingBehaviorAttribute att = (TextElementEditingBehaviorAttribute)Attribute.GetCustomAttribute(nextElement.GetType(), typeof(TextElementEditingBehaviorAttribute));
if (att != null && !att.IsTypographicOnly)
{
if (IsPartialNonTypographic(textReader, rangeEnd))
{
// Add pointer to ignore list
ITextPointer ptr = textReader.CreatePointer();
ptr.MoveToElementEdge(ElementEdge.BeforeEnd);
ignoreList.Add(ptr.Offset);
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
}
}
elementLevel++;
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
WriteStartXamlElement(/*range:*/null, textReader, xmlWriter, xamlTypeMapper, /*reduceElement:*/wpfPayload == null, preserveTextElements);
break;
case TextPointerContext.ElementEnd:
// Don't write Hyperlink end element if Hyperlink include the invalid
// in case of having a UiElement except Image or stated the range end
// before the end position of the Hyperlink or Hyperlink opening tag is
// skipped from WriteOpeningTags by selecting of the partial of Hyperlink.
if (ignoreWriteHyperlinkEnd && (textReader.GetAdjacentElement(LogicalDirection.Forward) is Hyperlink))
{
// Reset the flag to keep walk up the next Hyperlink tag
ignoreWriteHyperlinkEnd = false;
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
// Check the ignore list
ITextPointer endPointer = textReader.CreatePointer();
endPointer.MoveToElementEdge(ElementEdge.BeforeEnd); //
if (ignoreList.Contains(endPointer.Offset))
{
ignoreList.Remove(endPointer.Offset);
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
continue;
}
elementLevel--;
if (TextSchema.IsBreak(textReader.ParentType))
{
// For LineBreak, etc. use empty element syntax
xmlWriter.WriteEndElement();
}
else
{ //
// For all other textelements use explicit closing tag.
xmlWriter.WriteFullEndElement();
}
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
break;
case TextPointerContext.Text:
int textLength = textReader.GetTextRunLength(LogicalDirection.Forward);
char[] text = new Char[textLength];
textLength = TextPointerBase.GetTextWithLimit(textReader, LogicalDirection.Forward, text, 0, textLength, rangeEnd);
// XmlWriter will throw an ArgumentException if text contains
// any invalid surrogates, so strip them out now.
textLength = StripInvalidSurrogateChars(text, textLength);
xmlWriter.WriteChars(text, 0, textLength);
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
break;
case TextPointerContext.EmbeddedElement:
object embeddedObject = textReader.GetAdjacentElement(LogicalDirection.Forward);
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
WriteEmbeddedObject(embeddedObject, xmlWriter, wpfPayload);
break;
default:
Invariant.Assert(false, "unexpected value of runType");
textReader.MoveToNextContextPosition(LogicalDirection.Forward);
break;
}
}
}
示例3: WriteSimpleElement
/// <summary>
/// WriteSimpleElement
/// </summary>
/// <param name="xmlw"></param>
/// <param name="name"></param>
/// <param name="value"></param>
protected void WriteSimpleElement(XmlWriter xmlw, string name, string value)
{
if (value == null)
{
return;
}
xmlw.WriteStartElement(name);
xmlw.WriteChars(value.ToCharArray(), 0, value.ToCharArray().Length);
xmlw.WriteEndElement();
}
示例4: 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;
}
}
示例5: 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;
}
}
}
}