本文整理汇总了C#中System.Xml.XmlWriter.WriteBinHex方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteBinHex方法的具体用法?C# XmlWriter.WriteBinHex怎么用?C# XmlWriter.WriteBinHex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteBinHex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
//.........这里部分代码省略.........
示例2: WriteSerializable
private static void WriteSerializable( XmlWriter w, object o )
{
w.WriteAttributeString( "type", "Object" );
using( MemoryStream mem = new MemoryStream() )
{
BinaryFormatter f = new BinaryFormatter();
f.Serialize( mem, o );
byte[] buffer = mem.ToArray();
w.WriteAttributeString( "size", buffer.Length.ToString() );
w.WriteBinHex( buffer, 0, buffer.Length );
}
}
示例3: WriteXml
public void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("ID");
writer.WriteValue(id);
writer.WriteEndElement();
writer.WriteStartElement("nodeType");
writer.WriteValue((int)_cachedType.enumeratedType);
writer.WriteEndElement();
writer.WriteStartElement("parentNodeID");
writer.WriteValue(_parentNode.id);
writer.WriteEndElement();
writer.WriteStartElement("driverPort");
writer.WriteValue(_parentNode.Mydriver.getPort());
writer.WriteEndElement();
writer.WriteStartElement("driverEncrypt");
writer.WriteValue(_parentNode.Mydriver.usesEncryption());
writer.WriteEndElement();
if (_parentNode.Mydriver.usesEncryption())
{
writer.WriteStartElement("key");
writer.WriteBinHex(_parentNode.Mydriver.getKey(), 0, 16);
writer.WriteEndElement();
}
_parentNode.Mydriver.Dispose();
}
示例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: WriteBinaryData
/// <summary>
/// Write binary chunk data according to encoding type to xml script.
/// </summary>
/// <param name="writer">Xml writer.</param>
/// <param name="chunkEncoding">Encoding of the chunk.</param>
/// <param name="chunkData">Chunk data.</param>
private static void WriteBinaryData(XmlWriter writer, ScriptAcousticChunkEncoding chunkEncoding,
Collection<float> chunkData)
{
Debug.Assert(writer != null);
Debug.Assert(chunkEncoding == ScriptAcousticChunkEncoding.Base64Binary ||
chunkEncoding == ScriptAcousticChunkEncoding.HexBinary);
int bufSize = chunkData.Count * sizeof(float);
byte[] bytes = new byte[bufSize];
int bytesIndex = 0;
for (int i = 0; i < chunkData.Count; i++)
{
byte[] floatBytes = BitConverter.GetBytes(chunkData[i]);
for (int j = 0; j < sizeof(float); j++)
{
bytes[bytesIndex] = floatBytes[j];
bytesIndex ++;
}
}
switch (chunkEncoding)
{
case ScriptAcousticChunkEncoding.Base64Binary:
writer.WriteBase64(bytes, 0, bufSize);
break;
case ScriptAcousticChunkEncoding.HexBinary:
writer.WriteBinHex(bytes, 0, bufSize);
break;
}
}