|
I'm sorry, my english is not so very good. I'm a bit confused on what you mean regarding the code examples above. So option 2 is the better one if I undrestand correctly?
Or should I write it in a totally different way?
|
|
|
|
|
Yes. Option 2 is better.
It is better because it is easier to read.
It is also better because you are only Selecting a Single Node once.
Also if you need to change "XMLNODE.SelectSingleNode("@id").InnerText", then you only need to change it in one place.
|
|
|
|
|
The first, with:
Console.WriteLine
(
"{0}\n{0}\n{0}\n{0}"
,
XMLNODE.SelectSingleNode("@id").InnerText
) ;
|
|
|
|
|
Assuming that you actually need to do more work than just print the value 4 times, option 2 would be the better choice. It is more readable and will only allocate one string instance per loop where option 1 will allocate 4 string instances per loop.
You can also use the Attributes collection on the XmlNode object instead of a second call to SelectSingleNode . In either case, you should be aware that SelectSingleNode (or indexing the Attributes collection) can return null if the node (or attribute) isn't found, so you may want to test for that condition first.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Hi,
I have some simple XML and I want to convert the elements into strings.
My XML looks like this:
<ErrorDetail xmlns="mydomain.com/errordetail.xsd">
<RegVal AX="1" BX="2" CX="3" DX="3"</RegVal>
<RegVal AX="4" BX="3" CX="5" DX="4"</RegVal>
<RegVal AX="5" BX="4" CX="6" DX="5"</RegVal>
</ErrorDetail>
So I want to get the elements out into an array of strings like this:
strings[0] = "<RegVal AX="1" BX="2" CX="3" DX="3"</RegVal>";
strings[1] = "<RegVal AX="4" BX="3" CX="5" DX="4"</RegVal>";
strings[2] = "<RegVal AX="5" BX="4" CX="6" DX="5"</RegVal>";
But I want to do this using an XmlTextReader I think but I have not had success yet.
Can anyone help? Thanks
|
|
|
|
|
try the XmlNode.InnerXml property.
yourErrorDetailXmlNode.InnerXml should return a string containing the markup.
|
|
|
|
|
Hello all:
Can I document the (text or name) value of each item in the form . While the program executed , by pressing a button . I want txt file created and documents the values of the items >>>Any idea please<<<<<<br mode="hold" />
Thanks in advance
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
If by "item" you mean a form's control, yes. Just iterate over the form's Controls collection.
/ravi
|
|
|
|
|
Hello :
Thanks for your answer, yes I was mean a form control(radiobutton,checkboxes......etc), I want by pressing a button save thier (text&name) values . in a text file but I don't want to browse it , I want this txt file by pressing a save button created and save the status of these controls.
thanks in advance
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
As I mentioned, this is easy enough to do by iterating over the form's Controls collection and saving whatever information (i.e. properties of each Control ) you want.
/ravi
|
|
|
|
|
Hello :
Thanks for your answer, but what about the txt file, while the program executed how can I call it.....\
thanks in advance
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
It seems you may have taken on a task that's (currently) more complex than you can handle. I recommend coming up to speed with the basics of C#/WinForms programming before attempting this piece of work.
How to write to a text file[^]
/ravi
|
|
|
|
|
Thanks for you interested....
The way of Professional softwares start in two:
Simple codes and develop it.
Simple but effective ideas.
|
|
|
|
|
I've asked this before, but I didn't get an answer that fixed the problem.
Here is what I want to do:
I have a program that opens two applications (a Word document, and a hyperlink). It opens one after the other. What I'm trying to do is open the first application (the Word document) and AFTER the user closes the application, open the second one (the hyperlink).
I have tried using the boolean HasExited as well as the method WaitForExit(). Neither are working. As soon as the first application opens, the HasExited is false and WaitForExit() does nothing, even when I use the overloaded version.
Here is my code:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();<br />
psi.RedirectStandardOutput = true;<br />
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;<br />
psi.UseShellExecute = false;<br />
psi.Arguments = @txt_Wordfile.Text;<br />
psi.FileName = @WordExe[0];<br />
<br />
System.Diagnostics.Process WordProcess = new System.Diagnostics.Process();<br />
<br />
WordProcess = System.Diagnostics.Process.Start(psi);<br />
WordProcess.EnableRaisingEvents = true;<br />
WordProcess.WaitForExit(10000);<br />
<br />
System.Diagnostics.Process.Start(txt_websiteAddress.Text);
Please Help! Thanks!
|
|
|
|
|
danielhasdibs wrote: HasExited is false
That's as it should be.
|
|
|
|
|
Ok, would you care to explain further, please? Why is HasExited false when the user has not exited the process?
|
|
|
|
|
To indicate such.
Property Value
true if the operating system process referenced by the Process component has terminated; otherwise, false.
Remarks
A value of true for HasExited indicates that the associated process has terminated
modified on Friday, February 8, 2008 3:11 PM
|
|
|
|
|
HasExited... = Has the user exited?
The user HASN'T exited (false)
The user HAS existed (true)
Therefore, when HasExited==true then the application has exited!
|
|
|
|
|
For some reason, this does not work with MS Word. (at least on my computer)
|
|
|
|
|
Ok, is there anyone out there that actually has a solution to the problem?
|
|
|
|
|
danielhasdibs,
I don't have a solution, but i have an idea.
Start a new thread that is passed the process info that you start first, and then do a while loop. eg:
do
{
somet();
}
while (!process.HasExited)
LaunchUrl();
Only an idea and someone might point out something i have not thought of but have a go and see what happens.
Regards,
Gareth.
|
|
|
|
|
I tried it without success. Once again, the two applications started: one right after the other. If you have another idea, I'm all ears. Thanks.
|
|
|
|
|
Not with the approach you are using. It really is a pain to wait for thread exits in Windows. I usually give up in frustration and rely on load bearing for loops (yuk!).
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
danielhasdibs wrote: psi.Arguments = @txt_Wordfile.Text;
psi.FileName = @WordExe[0];
I'm wondering about these lines; why the at signs? Why the [0]?
Does Word start as expected?
WaitForExit() ought to do what you want.
|
|
|
|
|
I have tried many, many variations of the code above. I'm practically bald from me pulling my hair out.
I used the @ symbol because I saw it used in other code, but even without it, HasExited and WaitForExit do not work as expected. Ignore the string array and just assume it is a string (which it is). That's just how I need it for my particular piece of code.
However, the result of the code above are as follows:
The Word document opens, then immediately the hyperlink opens. There is no pause or anything.
|
|
|
|