|
I have a piece of code that recursively goes though all internal nodes of an xml document and prints out the Name of each node. However, whenever I try to print out the Value of the node, it is always null . Why is it always null ?
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
#endregion
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load("C:\\store.xml");
XmlElement root = doc.DocumentElement;
LoopThroughChildren(root);
Console.Read();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static void LoopThroughChildren(XmlNode root)
{
Console.WriteLine(root.Name + " - " + root.Value);
foreach (XmlNode n in root.ChildNodes)
{
if (n.NodeType == XmlNodeType.Element)
{
LoopThroughChildren(n);
}
}
}
}
}
/\ |_ E X E GG
|
|
|
|
|
When an xml node with text is loaded up into a dom, the text is not added as part of the element, but is added as a seperate child node of type text.
So something which looks like <MyNode>Hello</MyNode> in an xml file, would be represented within the dom as
Element Node - Name: MyNode
---- Text Node - Value Hello.
So when looping round the dom, to get the value of the MyNode element you need to access to first child and get it's value. root.firstChild.Value.
Or use the most helpful Text property instead root.Text.
Hope this helps....
|
|
|
|
|
Ah, thank you. I should have realized that. Also, you seem knowledgable about the xml dom. I have another question for you. Do you think it is wise to load a 50MB xml file into the dom? Is that pushing the limits? I do this at home and it can load it all in about 5 seconds, but here at work on a slower computer, it takes too long to wait for. I don't think I really need to use the dom eather, I'm not using any special funcitons from it. I think I should use the XmlTextReader instaed. What do you think?
/\ |_ E X E GG
|
|
|
|
|
I want to use the XmlTextReader instead of the XmlDocument. How can I use the below method with the XmlTextReader?
public void LoopThroughChildren(XmlNode root)
{
this.listBox1.Items.Add(root.Name+ " \t\t\t"+root.FirstChild.Value);
foreach (XmlNode n in root.ChildNodes)
{
if (n.NodeType == XmlNodeType.Element)
{
LoopThroughChildren(n);
}
}
}
I can't get an XmlNode out of the XmlTextReader....
/\ |_ E X E GG
|
|
|
|
|
It really depends on what you are trying to do with
the xml document.
A 50 MB document loaded into the DOM is quite big, but if you want to edit it then you will have to.
From what I cal tell though all you really want to do is read the document and add the element's name and text value to a list.
The XmlTextReader is ideal for this, as it is only reading a stream, and not creating objects in memory for each node, However this is not going to return you XmlNode's as it is not a dom implementation.
Take a look at the documentation, you will need to call Read() to move along each element, then you can access the Name and Value property of the XmlTextReader to get the data you want I think.
|
|
|
|
|
Hello,
Now, I tried to develop XMLWebService using C#.
This have a function managing data from/to Oracle database(10g).
But I think about database transaction.
(for example, I execute some stored procedure at the same time
(or without a break). After executed them, issue commit or rollback.)
So, I would like to use MTS, so I think it will manage it.
I am looking for some informations of it, but it is a few.
If you have some informations, how to do, alternative ways,
please tell me.
I have a trouble...
best regards,
yu-yu
|
|
|
|
|
hi all, in vs.net, how do you make a scroll bar automatically drop to the bottom of a multiline textbox?
its for my chat program, and scrolling down every message is getting annoying >=(
|
|
|
|
|
Refer the below code
const int SB_VERT = 1;
const int EM_SETSCROLLPOS = 0x0400 + 222;
[DllImport("user32", CharSet=CharSet.Auto)]
public static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);
[DllImport("user32", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam);
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
public POINT()
{
}
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
int min, max;
GetScrollRange(richTextBox1.Handle, SB_VERT, out min, out max);
SendMessage(richTextBox1.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max - richTextBox1.Height));
|
|
|
|
|
I have a class inherit from usercontrol, If a user at ime mode, the KeyDown Event can only receive the first key code, others are gone? How to get full strings? thanks!
|
|
|
|
|
1.I did not get what really the problem is? can you post the keypress event code.
2.Just to remind you,when ever Key is Pressed, the event gets fired and it gives one keycode at a time. that is what it is doing in your case?????
|
|
|
|
|
How to convert this into c#?
If File.Exists(filepath)Then
Dim filename As String = Path.GetFileName(filepath)
Thank You
|
|
|
|
|
string filename;
if(File.Exists(filepath)
{
filename = Path.GetFileName(filepath);
}
|
|
|
|
|
hi,
try
{
string fName="";
if(File.Exists(@"C:\sree.rtf"))
{
fName=Path.GetFileName(@"C:\sree.rtf");
MessageBox.Show(fName);
}
else
{
MessageBox.Show("File Does Not Exists");
}
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Thanx for ur contribution!;)
|
|
|
|
|
Hello,
What I want to do I allow the user to move/resize some of the controls on the form.
For example, if there is a textbox, the user would be allow to move it and resize it. Do I just monitor the mouse move event and check if it is within a certain distance of the textbox, and if it is, change the cursor to a gripper, and then, if the mouse is clicked, just change the width/height of the textbox accordingly?
Any ideas/suggestions are welcome
Thanx,
-Flack
|
|
|
|
|
I had the practice code for moving the controls. I am pasting the same for your reference. I do not know whether it would help you or not?
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Form2 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.BackColor = System.Drawing.SystemColors.Window;
this.button1.Cursor = System.Windows.Forms.Cursors.IBeam;
this.button1.ForeColor = System.Drawing.SystemColors.WindowText;
this.button1.Location = new System.Drawing.Point(136, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 88);
this.button1.TabIndex = 7;
this.button1.Text = "button1";
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.button1_MouseUp);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(608, 382);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main() { Application.Run(new Form2()); }
private System.Windows.Forms.Button button1;
int MoveFlag = 0;
private void button1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
MoveFlag = 1;
}
private void button1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
MoveFlag = 0;
}
private void button1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (MoveFlag == 1)
{
button1.Location = (new Point(button1.Location.X+e.X,
button1.Location.Y+e.Y));
button1.Refresh();
}
}
}
}
|
|
|
|
|
Hi guys,
I need to build a small application that will browse a website automatically. It needs to authenticate itself by using a form post, then a session id is given by the server, and I need to keep that session open for everything I'll do thereafter (or I'll be brought back to the login page).
I'm not quite sure where to start to achieve such a thing. Can anyone help?
Thanks!
Carl
|
|
|
|
|
You'll need to add a CookieContainer to your web request.
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(yoursite);
wr.CookieContainer = new CookieContainer();
Your client will then make subsequent request on the same session.
I suggest having a single static CookieContainer somewhere in your application and re-use that.
|
|
|
|
|
Armand,
I will try that, thank you!
Carl
|
|
|
|
|
Hi all. I know this is not C# specific but it is the language I am using for this project.
In my application I am setting permissions to several folders. Problem is, my app needs to run in 12 different languages. These permissions needs to be given to standard windows groups like 'Administrators' and 'Users' which change in every given language. Only solution I have found so far is to use a utility like this to give the permission based on the SID, which is constant for the standard groups given any OS language.
So is here any way in the framework or as an alternative an API I can call to get the localized name of the standard user groups?
Thanks!
Juan Miguel Venturello
|
|
|
|
|
Hi,
I am trying to convert the long integer (ex: 8837225770433) into character array.
But I am getting the following error.
"Value was either too large or too small for a character."
I am trying to convert the C++ logic to C#.
<br />
unsigned long* pTemp= reinterpret_cast<unsigned long*>(szBuf+(n-1)*4);<br />
*(pTemp) = hashRand.GenRandom() ^ lBuf[n];<br />
TIA
Dy
|
|
|
|
|
In C# you can do:
long value = ...;
char[] chars = value.ToString().ToCharArray();
that is if you want char array for 123 to hold '1', '2', '3'
|
|
|
|
|
well, he means byte (8), not char (16)
|
|
|
|
|
He said character array, not byte array.
|
|
|
|
|
Does C# have the C++ equivalent of a friend class?
I have a class where I want to prevent all by one class (in the assembly) from calling certain methods. In C++ I'd declare them protected and then make that one class a friend. Am I out of luck with C# as I suspect?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|