Click here to Skip to main content
16,015,218 members
Home / Discussions / C#
   

C#

 
GeneralSocket Communications between C++ and C# Pin
Jason Douglas29-Mar-02 6:55
professionalJason Douglas29-Mar-02 6:55 
GeneralRe: Socket Communications between C++ and C# Pin
James T. Johnson29-Mar-02 21:11
James T. Johnson29-Mar-02 21:11 
Generalconverting images Pin
29-Mar-02 4:21
suss29-Mar-02 4:21 
GeneralRe: converting images Pin
James T. Johnson29-Mar-02 21:22
James T. Johnson29-Mar-02 21:22 
GeneralRe: converting images Pin
vaMope1-Apr-02 7:41
vaMope1-Apr-02 7:41 
QuestionMemDC replacement? Pin
Zombies with Coffee, LLC29-Mar-02 4:14
professionalZombies with Coffee, LLC29-Mar-02 4:14 
AnswerRe: MemDC replacement? Pin
Zombies with Coffee, LLC29-Mar-02 4:25
professionalZombies with Coffee, LLC29-Mar-02 4:25 
GeneralSOAP serialization is too slow to accept Pin
29-Mar-02 1:52
suss29-Mar-02 1:52 
well, although i like to store my data into xml style, i find the .net's SOAP serialization is too slow to accept.

To state my opinion i think it better to show you what i am doing. althouth i hate to take up too much space in codeproject.

i write a simple xml schema as example
a schema to describe a book ---- book.xsd
======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by nova (RSGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="article">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="abstract" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="book">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="article" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
======================================================================

a implementation of schema ---- book.xml
======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by nova (RSGS) -->
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\vcnet_proj\book.xsd">
<article>
<title>first</title>
<abstract>first article</abstract>
</article>
<article>
<title>second</title>
<abstract>second article</abstract>
</article>
</book>
======================================================================

Framework provide a tool call xsd.exe to get a class from schema, I take it make book.cs
======================================================================
using System.Xml.Serialization;


/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public class article {

/// <remarks/>
public string title;

/// <remarks/>
public string @abstract;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="ID")]
public string id;
}

/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute("book", Namespace="", IsNullable=false)]
public class book {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("article")]
public article[] article;
}
========================================================================

Then make a simple demo to serailize the class ----usebook.cs
========================================================================
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

public class Test
{
book mybook;
public static void Main(string[] args)
{
Test t = new Test();
DateTime time1,time2;
time1=DateTime.Now;
t.DeserializeObject(@"book.xml");
time2=DateTime.Now;
TimeSpan span;
span=time2-time1;
Console.WriteLine("Cost {0}",span);
t.Tell();
}

private void DeserializeObject(string filename)
{
Console.WriteLine("Reading with XmlReader");

// Create an instance of the XmlSerializer specifying type and namespace.
XmlSerializer serializer = new
XmlSerializer(typeof(book));

// A FileStream is needed to read the XML document.
FileStream fs = new FileStream(filename, FileMode.Open);
XmlReader reader = new XmlTextReader(fs);

// Use the Deserialize method to restore the object's state.
mybook = (book) serializer.Deserialize(reader);

}

private void Tell()
{
Console.WriteLine("Dump information");
for (int i=0; i<mybook.article.Length; i++)
Console.WriteLine("{0}",mybook.article[i].title);
}
}
========================================================================

Okay!!
I will show you the effience i meet in my P4 256M pc.

=============================
D:\vcnet_proj>usebook
Reading with XmlReader
Cost 00:00:00.5808352
Dump information
first
second
=============================

Do you think it acceptable? So simple a object cost it almost 1 second to process?
But i find it will not get the time longer when i paste the articles in book element to hundreds more.
What are the .net doing in this second?


GeneralRe: SOAP serialization is too slow to accept Pin
Tim Smith29-Mar-02 2:18
Tim Smith29-Mar-02 2:18 
GeneralRe: SOAP serialization is too slow to accept Pin
29-Mar-02 2:58
suss29-Mar-02 2:58 
GeneralRe: SOAP serialization is too slow to accept Pin
Stan Shannon29-Mar-02 2:26
Stan Shannon29-Mar-02 2:26 
GeneralRe: SOAP serialization is too slow to accept Pin
James T. Johnson29-Mar-02 3:25
James T. Johnson29-Mar-02 3:25 
QuestionHow can i get the local time? Pin
29-Mar-02 0:18
suss29-Mar-02 0:18 
AnswerRe: How can i get the local time? Pin
Mazdak29-Mar-02 0:18
Mazdak29-Mar-02 0:18 
GeneralRe: How can i get the local time? Pin
29-Mar-02 1:57
suss29-Mar-02 1:57 
GeneralPrintPreview Dialog Pin
Mazdak29-Mar-02 0:01
Mazdak29-Mar-02 0:01 
GeneralRe: PrintPreview Dialog Pin
James T. Johnson29-Mar-02 21:24
James T. Johnson29-Mar-02 21:24 
GeneralRe: PrintPreview Dialog Pin
Mazdak29-Mar-02 22:35
Mazdak29-Mar-02 22:35 
GeneralRe: PrintPreview Dialog Pin
James T. Johnson29-Mar-02 22:46
James T. Johnson29-Mar-02 22:46 
GeneralRe: PrintPreview Dialog Pin
Mazdak29-Mar-02 23:52
Mazdak29-Mar-02 23:52 
GeneralRe: PrintPreview Dialog Pin
James T. Johnson30-Mar-02 9:37
James T. Johnson30-Mar-02 9:37 
GeneralRe: PrintPreview Dialog Pin
Mazdak30-Mar-02 19:08
Mazdak30-Mar-02 19:08 
QuestionHow to get a list of databases in .NET Pin
spbdenis28-Mar-02 10:27
spbdenis28-Mar-02 10:27 
AnswerRe: How to get a list of databases in .NET Pin
29-Mar-02 13:10
suss29-Mar-02 13:10 
GeneralFilter Dataview Pin
Mazdak27-Mar-02 22:21
Mazdak27-Mar-02 22:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.