|
Thanks but a totaly out of context link to umpteen methods doesn't really point me to the best/fastest way of retriving a single value from an XML file.
Any chance of being more specific?
What I'm after is a way of storing/reading a config file in XML rather than a txt file.
But i wont bother if every method is a lot more convaluted than doing a Readline() on a text file stream.
I was a nice simple way to read an xml value from a given element.
|
|
|
|
|
The easiest way it to use XmlSerialize Class.
Just give your instance to that class, then it will be automatically converted to Xml file.
Or just give the filename, then you can deserialize it, and you get an instance of your class.
|
|
|
|
|
The easiest way is with an XPath query, so if you have a simple document, say:
<Config>
<Name>MySetting</Name>
</Config>
you would load that into an XmlDocument instance using the Load or LoadXML methods, so:
XmlDocument xmlDoc = new XmlDocument();<br />
xmlDoc.Load("C:\myConfig.xml");
XmlNode nameTextNode = xmlDoc.DocumentElement.SelectSingleNode("Name/text()");
string name = nameTextNode.Value;
You can read any value from the xml document with the correct xpath query. XPath is quite a big subject, and takes some getting used to, but there is an Xml forum here for specific path questions.
Note that the above code was written quickly and is untested, it is just to illustrate the sequence... it may not compile but should give you an idea to start playing with.
---
How to get answers to your questions[^]
|
|
|
|
|
|
Hi All,
I have a Client/Server App like VNC developed in C# where server sends the updated regions of its screen as compressed buffer to connected client. Client upon receiving the updates draw them approp. I have used windows hooks to inform my server app about the updates on the screen using windows messages.
I have added MessageFilter to my server app thread to receive my custom messages of screen updates from my hooking dll. The problem is that currently i m using an ordinary approach where i creates a rectangle and make union of it with other incomming rectangular region updates from dll. On the other side i have a thread that receives the final rectangle, clears the rectangle varibale of the messagefilter, take a screenshot of that final rectangle, compress it and send it to the client. This process repeats and each unioned rectangle is captured and sent to the client.
My problem is that in this approach a lot of updates like menu selection, text cursor, text etc. are missed.
Can somebody give me suggestion how can i improve this.
Another approach is to use Win32 Region where each rectangle is added to the Region and hence no chance of missing rectangle. But i need a pseudocode or code snippet if i want to use this one.
Thanx.
"Imagination is much more important than implementation"
|
|
|
|
|
Rashid.Mahmood wrote: and make union of it with other incomming rectangular region updates
Doesn't this just slow the process down (then you miss bits) isn't it better just to send each rectangle as it's updated rather than creating a new rectangle (which they'll be a slight delay, and loss of information if not fast enough).
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
U r quite right but here are some issues that enforces us to crrate a slight delay:
1. Clinet machine's drwaing speed
2. If i continuously capture each rectangle bitmap using Bitblt and then compress it to stream and then send it client then my CPU usage on server side reaches to upper limit.
So in this situation what should i do.
Thanx
"Imagination is much more important than implementation"
|
|
|
|
|
To be honest I would think that C# isn't quite quick enough to do this kind of thing unless you have a very fast machine. As a simple benchmark why don't you try (if you have a fast network) doing the streaming without compression.
If this is reasonable then you may need to come up with a faster compression and decompression algorithm (there are some benchmarks at http://www.7zip.org[^] I think ).
If it is too slow then either you'll need better performing functions and methods or (unfortunately) change to using either C++ or unsafe code in C#.
It might be worth trying C# with unsafe code (i.e. pointers etc) before trying the C++ route.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
Hi All
In my application i read from some log file ( file name is XXX.log ).
I read line by using ASCIIEncoding - but when i read some line that contain the char '-' i see in the debug variable that i got the char '?' beside '-'.
What to do ?
Please someone can help me ?
|
|
|
|
|
If your log file in ASCII format, then you can read it using this code:
using(StreamReader sr = new StreamReader("XXX.log", Encoding.ASCII))
{
while(sr.Peek() >= 0)
{
string text = sr.ReadLine();
}
}
If your log file in Unicode, then change the Encoding.ASCII to Encoding.Unicode
|
|
|
|
|
Maybe there is some other solution ....
|
|
|
|
|
Can anyone tell me how to escape the dollar signs in a code snippet?
As a first attempt at writing a code snippet I've hit a bit of a snag. It seems that, what I thought would be a fairly simple first attempt, isn't.
I attempted to create a snippet so I could insert a block of code that the version control system could use to add its log message to the source file.
i.e.
#region Source Control File Version Log
#endregion
However, it seems in my haste I didn't realise that the $blah$ is supposed to be expanded out to something else when the snippet is inserted. When I insert the snippet in to the code a blank appears where $History: $ appears.
I've had a look around and I can't see anything about escaping the dollar signs (so I'm obviously looking in the wrong places).
Scottish Developers events:
* .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy
* Developer Day Scotland: are you interested in speaking or attending?
My: Website | Blog
|
|
|
|
|
|
Hello,
Any ones help would be greatly appreciated on this.
We have a webservice that invokes a dll and a c# .Net windows application. Is there anyway thay would enable the Dll invoked by the webservice to invoke a function in the windows application???? given that the application is runing of course.
And another question is:
Is there a way for a windows application written in C# to call a function in a running windows service??? like a function that will cause the windows service to update itself???
any help will be greatly appreciated
thanx
|
|
|
|
|
hi,
how can i find a given number using binary search?
thank you.
arun
|
|
|
|
|
Binary search in what? In an array, in a file, in any stream?
_____________________________________________________________________________
I don't expect too much, all I want is your vote for Halbsichtigkeit.
|
|
|
|
|
|
I rated this question as a '1'. I highly recommend you read Chris' sticky post on 'How to get your questions answered'. First, your subject does not provide any input for what area you are looking for help on. Second, your question is so generic that no one could possibly answer your question!!! Finally, your question does not indicate what you have tried.
CodeProject is not here to do your job, to do your work, to do your research for you. CodeProject is a group of developers that help other developers with new features, articles with plenty of how-to's, and help to a developer who is trying to do something and getting stuck.
As to your question, I googled Binary Search and got not only a definition but also a code sample. Then looking at the code sample it looks like it could be an IComparer implementation that may easily fit into a custom collection definition. So I would suggest you begin working like a developer.
|
|
|
|
|
Hello, I have a function written in C++ that return a wchar_t*. I don't know how can I receive the data in a C# program.
I can I have 2 type of my C++ function:
1) void GetDestFromSource(char *pSourceString, wchar_t *pDestinationString);
2)wchar_t *GetDestFromSource(char *pSourceString);
In my C# program I try some kind of prototype for the first C++ function but they don't work:
[DllImport("MyDll.dll")]
1 Attempt) public static extern void GetDestFromSource(string pSourceString, string pDestinationString);
2 Attempt) public static extern void GetDestFromSource(string pSourceString, out string pDestinationString);
3 Attempt) public static extern void GetDestFromSource(string pSourceString, StringBuilder pDestinationString);
4 Attempt) public static extern void GetDestFromSource(string pSourceString, out StringBuilder pDestinationString);
In my C# program I try some kind of prototype for the second C++ function but they don't work:
[DllImport("MyDll.dll")]
1 Attempt) public static extern string GetDestFromSource(string pSourceString);
2 Attempt) public static extern StringBuilder GetDestFromSource(string pSourceString);
All the attempts don't work. Can anyone help me? Thank you very much for any answer.
SD3
|
|
|
|
|
I got the following problem I have a class that contains a List<t> member.
I want the users to have access to that list, but only to read the data. So I implemented a property that returns the list.
The list is indeed readonly meaning I can^t add remove or change any references in the list. However I can change the values of the references. Is there anyway I can avoid that?
simple example:
The basics of the wrapper
<br />
class listWrapper<X> where X : class<br />
{<br />
private List<X> myList;<br />
public List<X> TheList <br />
{ <br />
get { return myList.AsReadOnly(); } <br />
}<br />
public listWrapper()<br />
{
<br />
}
For the sake of the example a simple class with a property
<br />
class SomeObject<br />
{<br />
private int aProp;<br />
public int ACertainProp<br />
{<br />
get { return aProp; }<br />
set { aProp = value; }<br />
}<br />
}<br />
And finally a class using the wrapper
<br />
class AnotherClass<br />
{<br />
public void Method()<br />
{<br />
listWrapper<SomeObject> wrapper = new listWrapper<SomeObject>();<br />
<br />
SomeObject anObject = wrapper.TheList[0];<br />
anObject.ACertainProp = 15;
}<br />
}
|
|
|
|
|
You can either make your SomeObject immutable.
eg:
class SomeObject<br />
{<br />
private bool immutable = false;<br />
private int aProp;<br />
public int ACertainProp<br />
{<br />
get { return aProp; }<br />
set { if (!immutable) aProp = value; }
}<br />
<br />
public void MakeImmutable()<br />
{<br />
immutable = true;<br />
}<br />
}
however this might not be what you are looking for? this makes the object immutable for every consumer.
another approach might be to simply clone your objects and fill the list with clones.
the clones wont be readonly (unless also supporting immutable)
this might be useful if your main concern is just to avoid that people change your data.
you could also try making wrappers for your objects, where the wrapper and the SomeObject shares the same interface.
either way, there is no good approach to make an object readonly out of the box, you have to write a bit of code no matter what approach you select.
Id probably go for immutable clones.
foreach (SomeObject obj in realList)<br />
{<br />
SomeObject clone = obj.clone();<br />
clone.MakeImmutable();<br />
resultList.add(clone);<br />
}
//Roger
http://www.puzzleframework.com
[edit]
forgot to say , wrappers have an edge over clones because a wrapper will always reflect the real values of the real objects properties.
a clone will just reflect the values of the properties of the real object when the cloning was done.
|
|
|
|
|
Hi,
We have to save a datetime in the database in format: "yyyyMMddHHmmssff".
For this we can use the ToString method, no problem here.
But I can't find how to set the DateTime object back again when we read out that value from the database.
I've looked into Convert.ToDateTime and TryParse , TryParseExact methods, but somehow I can't find what I'm looking for.
How can you set a DateTime object from a string with that format?
thanks !!
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
There is overload of DateTime.TryParseExact[^] that takes a format string.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
mmm, Must of looked over that one. I'll try it thanks.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
V. wrote: We have to save a datetime in the database in format: "yyyyMMddHHmmssff".
Why? Can't you store it as a datetime value?
---
b { font-weight: normal; }
|
|
|
|