|
|
All,
Just wondering if it is possible to parse XML from a string in memory, as opposed to a file? I'm getting XML data over a TCP/IP connection, and it is read into a string in memory. I could dump the string to a file, then parse the filename to XmlTextReader, but that seems like a waste of resources.
Any pointers would be appreciated.
Cheers,
Andrew
|
|
|
|
|
Hi Andrew,
there are some solutions:
1st)
If you only want an XmlDocument, use the methode LoadXml of the XmlDocument class.
<br />
string myXmlContent = @"<GoodSides><Side name='CodeProject'>http://www.codeproject.com</Side></GoodSides>";<br />
XmlDocument xmlDoc = new XmlDocument();<br />
xmlDoc.LoadXml(myXmlContent);<br />
2nd)
Copy the bytes (or strings) to a MemoryStream.
<br />
byte[] myContent = ...;<br />
MemoryStream memStream = new MemoryStream(myContent);<br />
XmlTextReader xmlReader = new XmlTextReader(memStream);<br />
or
<br />
MemoryStream memStream = new MemoryStream();<br />
StreamWriter memWriter = new StreamWriter(memStream);<br />
memWriter.Write(@"<GoodSides>");<br />
memWriter.Write(@"<Side name='CodeProject'>http://www.codeproject.com</Side>");<br />
memWriter.Write(@"</GoodSides>");<br />
memStream.Position = 0;
XmlTextReader xmlReader = new XmlTextReader(memStream);<br />
3rd)
Implement a own class with Stream as BaseClass.
This class can read the datas direct from TCP/IP.
<br />
class MyOwnStream: Stream<br />
{<br />
int Read(byte[] buffer, int offset, int count)<br />
{<br />
...<br />
}<br />
};<br />
MyOwnStream myStream = new MyOwnStream(...);<br />
XmlTextReader xmlReader = new XmlTextReader(myStream);<br />
4th)
Use the SocketStream direct. (If the stream contains only the xml data and no more.)
<br />
NetworkStream myNetworkStream = new NetworkStream(mySocket);<br />
XmlTextReader xmlReader = new XmlTextReader(myStream);<br />
Hope, it helps
Niedzi
|
|
|
|
|
how can I get message I want in a textbox after checking a chekbox?
|
|
|
|
|
Use CheckBox.CheckedChanged event:
checkBox1.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged);
And then implement this handler:
void CheckBoxOnCheckedChanged(object obj, EventArgs ea) {
textBox.Text = message;
textBox.Invalidate(); // you shouldn't use this line, but...
}
|
|
|
|
|
I have a hierarchy of objects. For simplicity's sake, let's say I have a TreeView containing a hierarchy of TreeNodes.
I'd like to add these TreeNodes to an ArrayList, with the top-most level TreeNodes being added at the beginning of the list, 2nd-level TreeNodes added next, 3rd level nodes after that, and so on.
Anyone know of an efficient algorithm to do this? Or should I just resort to manually going down each hierarchy level, adding each node to the list as I go along?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
This is not a depth-first tree traversal, so you probably need to create array of arrays:
<br />
ArrayList[] lists = new ArrayList[DEPTHS_COUNT];<br />
then go through all nodes using recursion:
<br />
void Traverse(TreeNode tn, ref ArrayList[] lists, int depth) {<br />
<br />
lists[depth].Add(tn);<br />
<br />
if (tn.Nodes.Count > 0)<br />
foreach (TreeNode node in tn.Nodes)<br />
Traverse(node, ref lists, depth + 1);<br />
}<br />
...and the last step is to split lists into one list:
<br />
ArrayList nodeList = new ArrayList();<br />
<br />
foreach (ArrayList list in lists)<br />
foreach (TreeNode tn in list)<br />
nodeList.Add(tn);<br />
Is that what you need?
|
|
|
|
|
Hi Judah,
It's not difficult.
Use following call
ArrayList = ListOfTree(myTree);
and implement ListOfTree with this:
static ArrayList ListOfTree(TreeView tree)
{
ArrayList list = new ArrayList();
<small>
list.AddRange(tree.Nodes);
<small>
for (int idx = 0; idx < list.count; idx++)
{
list.AddRange(((TreeNode)list[idx]).Nodes);
}
<small>
return list;
}
Example:
You have this tree:
Tree
|-A1
| |-B1
| | |-C1
| | +-C2
| +-B2
| +-C3
+-A2
+-B3
First you add the Nodes of the tree:
List := A1 A2 [from Tree]
Second you add each child of the already listed nodes: A1 A2
List := A1 A2 B1 B2 [from A1]
List := A1 A2 B1 B2 B3 [from A2]
And so on for each child of B1 .. B3
List := A1 A2 B1 B2 B3 C1 C2 [from B1]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from B2]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from B3]
And so on for each child of C1 .. C3
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C1]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C2]
List := A1 A2 B1 B2 B3 C1 C2 C3 [from C3]
Have fun,
Niedzi
|
|
|
|
|
|
|
How to show information about a picture in a picture box when put mouse over?
|
|
|
|
|
Label myLabel = new Label();
myLabel.Text = "here is an interesting pic";
myPictureBox.Controls.Add(myLabel);
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Hi
Okay, this is my first post so please bear with me..
Anyhow. I'm working on an oldish MFC application that uses dlls as 'plugins' - similar to Photoshop, Cubase etc. Now as part of my attempts to bring some of this kicking and screaming up to date, I'm trying to add another dll for use, written in C#.
I've done the 'use managed extensions' trick, and can instantiate the C# dll by adding it as a reference, and all seems to behave as expected - but I'm having some difficulty then handling the C# form's OK/Cancel. Ideally, I'd like any information or data contained within the C# form to be passed back to the MFC form - more as a verification that whatever the dll is supposed to do has been carried out successfully or not (plus as a demo of language interoperability it seems a good idea to persuade the nay-sayers).
I figure it's going to be done through interop - so pass a handle to the parent CWnd to the the C# dll, and then post a message to it once the dll 'ok' button is pressed - but where is my main starting point for going about this? Is this the best way to go about it, or is there something I've overlooked?
thanks,
benwalker
|
|
|
|
|
Do you have control over when the C# form is launched? If so, can't you just go (in Managed C++):
DialogResult result = launchedForm->ShowDialog();
if(result == System.Windows.Forms.DialogResult::OK)
{
}
Maybe I'm not understanding your problem.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
hmm. now why didn't I think of that one - well, it saves going through interop or something else. I forget the fact that managed c++ has access to the same type of messages.. anyway - that seems to work:
thanks
benw
|
|
|
|
|
Hi,
My application needs to login to a web site automatically. Is it a way to programtically fill in the username and password web fields from a .NET windows form?
Thanks.
|
|
|
|
|
Is there a program where I allow the user to pick an Image from a Windows form and allow them to make that into a desktop WallPaper.
sahoREGS
|
|
|
|
|
I'm not sure if there is something in the .NET library, but if all else fails you can use the API call SystemParametersInfo() to do it.
Matt Gerrans
|
|
|
|
|
There's a registry key for something like that:
HKEY_CURRENT_USER\Control Panel\Desktop\
There you've got some values like ConvertedWallPaper, OriginalWallpaper, Wallpaper enz.
Hope this helps!
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
hi
can anyone tell me that can we create a button array if we can then how we will display a button using that array on the form or write text on that button.
please tell me soon
|
|
|
|
|
Why do you need to create button array? I don't know what are you working on, but array of buttons can be initialized as well as any other array:
Button[,] abtn;
of if you want jagged array, use:
Button[][] abtn;
Then traverse all buttons using for cycle and set their properties:
Button btn = Button[3, 2];
btn.Size = btnSize;
btn.Parent = this;
...
|
|
|
|
|
actually i have already create an array like but it does'nt work for its properties.
ok let me explain actually i want 64 button. and i get user input not through button through textbox. input is obviously string and every input word has specific meanging like if input is C1 its means 3rd button.
initially there is some specific text on16 button from start and 16 button from the end.
if user give 3rd button for source and 7th button for destination then text displayed on the source button is replaced to des button and source button will become blank. can u tell me how i will handle it.
|
|
|
|
|
input is obviously string and every input word has specific meanging like if input is C1 its means 3rd button
Then why not use a hashtable, with string keys and button values?
using System.Collections;
...
Hashtable table = new Hashtable();
table.Add("C1", buttons[2]);
table.Add("C2", buttons[14]);
... and so on
Then when you need to access a button based off textbox input, go
string userEnteredString = "C1";
Button button = (Button) table[userEnteredString];
Is this what you're looking for?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
ok this works. but what i want it is not working for it.
please help me .
i am explaing my problem in detail. first of all i want 64 buttons (like 8 rows and 8 columns )on my from.and i have to textbox one is for source and one for destination input.user is restricted that he gave input like a1,b1,c1,d1,............a8,b8,d8.after getting source and destination input i want to set if user gave in source tetxbox c1 its means source is 2 like this for destination.and i know these are also source and destination button numbers.
then i want to pass this inputs to a function. after some validation when function returns that source and destination is valid i want to replace source button text to destination button text. and source button text become null.how i will find out that which button tag value is equal to source also for destination and then on this basis i will change it.
please tell.......soonnnnnnnnnn
|
|
|
|
|
We can definately create button array.
Button []btnArr = new Button[5];
for(int i = 0; i < 5; i++)
{
btnArr[i] = new Button();
btnArr[i].Text = "TestButton";
btnArr[i].Visible = true;
btnArr[i].Width = 50;
btnArr[i].Height = 20;
this.Controls.Add(btnArr[i]);
}
Give location also and it will work.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|