|
Sorry, didn't realize is was going to strip out the XML stuff. I'll try again.
I am trying to write then read my first XML file. It is meant to store settings for a device. The user will store stuff to the file, then maybe load it back and transmit it to the target board. Sounds pretty simple.
My question is how to parse this guy. How do I get the data back out so I can plop it on the forms I've created? I see how to rifle through the file, but now how the heck to see where I am. I'm very new to this, so a real-world example would be great.
Here's how I'm setting up to do the read.
StreamReader stream = new StreamReader(fi.FullName);
XmlTextReader reader = new XmlTextReader(stream);
XmlSchemaCollection schemaColl = new XmlSchemaCollection();
schemaColl.Add(null,"XMLSchema_LCData.xsd");
XmlValidatingReader valReader = new XmlValidatingReader(reader);
valReader.ValidationType = ValidationType.Schema;
valReader.Schemas.Add(schemaColl);
valReader.ValidationEventHandler += new ValidationEventHandler(valHandler);
while (valReader.Read())
{
// Now what? How would I know that I have some certain piece of data?
// Pretend I want to know that is the FINV0 for CreepB from the XML file.
}
Here's the XML file I am trying to parse:
<?xml version="1.0"?>
<XMLSchema_LCData xmlns="http://tempuri.org/XMLSchema_LCData.xsd">
<DateSaved>2/25/2005 1:51:54 PM</DateSaved>
<SoftwareName>X-RES</SoftwareName>
<SoftwarePartNumber> 172814r</SoftwarePartNumber>
<SoftwareVersion>0.1.0</SoftwareVersion>
<SerialNumber>someCell</SerialNumber>
<PartNumber>somenumber</PartNumber>
<AD_Configuration>
<RoughCal>40.591</RoughCal>
<TempGain>11.95457</TempGain>
<TempOffset>-884002</TempOffset>
<TempOffset>16</TempOffset>
<InputQR>40</InputQR>
<OutputDecimator>1</OutputDecimator>
<TemperatureDecimator>8</TemperatureDecimator>
<TemperatureQR>10</TemperatureQR>
</AD_Configuration>
<AD_Runtime>
<RetrainThreshold>120</RetrainThreshold>
<HysteresisThreshold>60</HysteresisThreshold>
<NoiseRequirement>4</NoiseRequirement>
<OpenLoopQR>255</OpenLoopQR>
<MaxQR>70</MaxQR>
<MinQR>20</MinQR>
</AD_Runtime>
<SystemTC>
<ZA>169666</ZA>
<ZB>0.01226807</ZB>
<ZC>-4.305039E-07</ZC>
<SB>4.582489E-08</SB>
<SC>-5.763168E-13</SC>
</SystemTC>
<Linearity>
<Cor>1.255103E-10</Cor>
<Gain>0.9998779</Gain>
</Linearity>
<Creep>
<CreepA>
<FinV0>6.496906E-05</FinV0>
<FinV1>0</FinV1>
<FinV2>0</FinV2>
<Tau0>0.001777649</Tau0>
<Tau1>0</Tau1>
<Tau2>0</Tau2>
</CreepA>
<CreepB>
<FinV0>4.994869E-05</FinV0>
<FinV1>0</FinV1>
<FinV2>0</FinV2>
<Tau0>0.0001777411</Tau0>
<Tau1>0</Tau1>
<Tau2>0</Tau2>
</CreepB>
<CreepC>
<FinV0>9.953976E-06</FinV0>
<FinV1>0</FinV1>
<FinV2>0</FinV2>
<Tau0>5.924702E-05</Tau0>
<Tau1>0</Tau1>
<Tau2>0</Tau2>
</CreepC>
</Creep>
<Hysteresis>
<Zero>119020</Zero>
<Span>968630</Span>
<GuardBand>200</GuardBand>
<Increasing>
<A_Term>0</A_Term>
<B_Term>0</B_Term>
<C_Term>0</C_Term>
<E_Term>-1.065821E-12</E_Term>
</Increasing>
<Increasing>
<A_Term>8E-05</A_Term>
<B_Term>-8.259087E-11</B_Term>
<C_Term>0</C_Term>
<E_Term>-1.065821E-12</E_Term>
</Increasing>
</Hysteresis>
</XMLSchema_LCData>
Any help?
Kenny O'Dell
Sr. R&D Software Engineer
Mettler-Toledo Inc.
Inman, SC
|
|
|
|
|
Use XmlDocument instead. Better performance for especially short XML files.
Here is an example:
<br />
private void Insert2XML(string strXmlFilePath, string PersonName, int ID, string Notes)<br />
{<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load(strXmlFilePath);<br />
XmlNode root = doc.DocumentElement;<br />
<br />
XmlNode Person = doc.CreateElement("Person");<br />
Person.SetAttribute("Name", PersonName);<br />
Person.SetAttribute("ID", ID.ToString());<br />
Person.InnerText = Notes;<br />
root.AppendChild(Person);<br />
<br />
XmlTextWriter writer = new XmlTextWriter(strXmlFilePath, null);<br />
writer.Formatting = Formatting.Indented;<br />
writer.Indentation = 4;<br />
doc.Save(writer);<br />
writer.Close();<br />
}<br />
<br />
private string GetPersonID(string strXmlFilePath, string PersonName)<br />
{<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load(strXmlFilePath);<br />
XmlNode root = doc.DocumentElement;<br />
<br />
XmlNode SearchNode = root.SelectSingleNode("//*[@Name='" + PersonName + "']");<br />
if (SearchNode != null)<br />
{<br />
return SearchNode.Attributes["ID"].Value;<br />
}<br />
else<br />
{return "Not Found!"}<br />
}<br />
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
The .NET TextBox control automatically provides a nice context menu that pops up when the user right-clicks in it with all the stuff expected, like Cut, Copy and Paste (and some surprising ones, like right-to-left selection, etc.). However, if you add a context menu component of your own you lose the one provided. Does anybody know a way to find and merge with the default menu? I've been trying to add an item to call a spell checker I've added to my project and don't want to have to duplicate all of the nice things the TextBox already provides on its default context menu... Any thoughts?
Thanks in advance for any help!
P.S. I posted this question in the .NET forum, too - I don't want to clutter up these boards with duplicates, but this area looked a bit more active so I thought I'd try here as well...
Mitchell
|
|
|
|
|
|
Thanks for the tip - I sure wish it could be easier, but at least you've given me a place to start!
Mitchell
|
|
|
|
|
I have a ListBox (CatList) and an ArrayList (Cats) bound to it. I'm removing the selected item in the ListBox from the ArrayList and rebinding the source after removing:
<br />
private ArrayList Cats = new ArrayList();
...<br />
...<br />
<br />
private void bRemoveCat_Click(object sender, System.EventArgs e)<br />
{<br />
int selIndex = this.CatList.SelectedIndex;<br />
<br />
this.CatList.DataSource = null;<br />
this.CatList.Items.Clear();<br />
<br />
Cats.RemoveAt(selIndex);<br />
<br />
this.CatList.DataSource = Cats;<br />
this.CatList.DisplayMember = "Name";<br />
this.CatList.ValueMember = "ID";<br />
}<br />
No exception is thrown when the above code is executed but after the code is executed, if I click on the ListBox, the exception below is immediately thrown.
<br />
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll<br />
<br />
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.<br />
What do you think? Thanks in advance.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
I'd verify the value of selIndex before you try and use it on the Cats arraylist.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I already did it Dave. Actually the item is removed properly. But the error occurs after this process (when I click anywhere on the ListBox)
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Using ASP.NET with C# I have two login screens for the application. One to get into the system and a second login screen, which is for administrator tasks. The first one redirects me to my default page with the method below. I have duplicated the code from the login page and im using it for my admin login page but do not want it to automatically redirect me to the default screen again. Instead I would like it to direct me to a page called administrator.aspx. how do I do this. Im New to c sharp. Small hurdle huh! Any help much appreciated.
Chris
if (id != null)
{
// Set the user as authenticated and send him to the
// page originally requested.
FormsAuthentication.RedirectFromLoginPage(id, false);
}
|
|
|
|
|
Please direct your ASP.NET-related questions to the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi, first of all try the ASP.NET forum as it would be more specified.
If my memory is correct, you can use the Response.
well for each aspx page there is HTTP support for REQUEST & RESPONSE.
you can use
this.response.redirect(...) method to redirect to another page.
Sorry, I don't know much asp.net.....but tried to help out anyway!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
Thanks for your advice. will try it out
|
|
|
|
|
hi everybody
is any bod know how to run desktop application from we page...As specially on web page..?
|
|
|
|
|
Try the Web Development[^] forum, although you should keep in mind that you can't coax a browser into starting an application without exploiting a security hole because to do so would be a serious security vulnerability if it were allowed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi All,
I am relatively new to c# and i am working in .NET 2003. I use very often a MessageBox, but sometimes it comes without a text on it, even if i have assigned a text to it (MessageBox.Show(stringVariable); ). The same happens to ComboBox and ListBox. They appear blank, although they are bound to the corresponding DataSource. Later (when the application is still running) appears the text suddenly. May be does anyone know the problem?
Very gratefull in advance,
Sailer
|
|
|
|
|
Your description offers almost no technical information that is necessary to help you. Please provide snippets of your code, including your data-binding code (just snippets though, please). It's probably that if you're getting data from the underlying data source your not taking the appropriate actions to get the right data. Debugging your application and stepping through your code is what you should do first. In Visual Studio, just open your project, set a breakpoint at the beginning of a method that uses MessageBox where the problem occurs, and hit F5 (Debug->Start Debugging).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Well a messagebox takes at least 2 parameters the caller and message,
Therefore I would suggest you to use it like this:
MessageBox.Show(this,StringVariable);
For the combobox & listbox, I would suggest you to loop through the datasource and insert an item every time! In this case, you can debug and it will be 1000% sure the items will be added!
Regards
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
Some people say that C# can't work with custom C++ interfaces. But at least I can see them in C# Object Browser.
Does anybody know the exact situation???
If C# does support custom interfaces how such type incompatibilities like byte[] and string can be handled???
Are there any botle necks???
Could it be faster using custom interfaces in C# instead of dispatch???
Vad
|
|
|
|
|
What do you mean by custom interfaces? C# classes can most definitely implement interfaces declared in C# that interop with native interfaces. I do it all the time, as COM interop is one of my fortés. You should start by reading Exposing .NET Framework Components to COM[^], since implementing a COM interface - if that is what you mean - would only make sense if you were trying to host your .NET Framework component in a COM client.
Strings and byte[] also marshal correctly and quite easily. Read Marshaling Data with COM Interop[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
By custom interfaces I mean those COM object, designed for C++ usage and inherited from IUknown interface, and not from IDispatch. Such COM objects do not contain definitions for Automation types, that clients such as VB can simply use.
Actually, my problem is: I have 2 COM libraries, implemented as set of Dispatch objects for automation and set of Custom objects for C++ usage. And I'd like to write my own DLL based on on of those sets. The main question is: what language should I use??? I tryed C# with Dispatch objects set and found it rather slow. So, maybe I can use C# and set of custom interfaces, or shall I switch to C++.NET???
|
|
|
|
|
What interface from which you derive doesn't dictate what types you pass as parameters. Even if you don't inherit from IDispatch (in managed code, using [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] or ComInterfaceType.InterfaceIsDual ) you can stil, for example, pass or return a SAFEARRAY .
Be suer to read those links I gave you in my first reply.
What you should be doing is using dual class interfaces, which expose interfaces for both VTBL binding (IUnknown ) and automation. Even automation-only interfaces can be used by C++, but it can be a pain.
See the documentation for the ComInterfaceType.InterfaceIsDual member in the .NET Framework SDK for more information.
As far as performance, keep in mind that not only are you marshaling to different components you're marshaling across native and managed boundaries. The Common Language Runtime (CLR) marshals data for you in most cases, and it can take time depending on what the data is. C++.NET won't solve things either, since you'll be compiling managed code which will also target the CLR. In fact, until C++ .NET 2.0 (Managed C++ 2.0, as it's more commonly called) performance even within MC++ can be bad because of data being marshaled from native to managed within the same DLL. It really just depends on what you're doing.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I am a beginner in C# and I have problem with reading and writing text file with code page WIN 125O or ISO 8859-2 (Czech)
Please how I must use StreamReader and StreamWriter and how I set codepage for this one.
Thank you for any answer
Libor Matejka
|
|
|
|
|
Hi
i have a treeView that is collection of Person object(each person has ID and Name ).
this treeView has infinit depth because a person can be child of other person.
i want to trace the treeView and check IDs but i dont what to do?
|
|
|
|
|
You can recursively traverse the tree, starting from the root(s). Something like
<br />
foreach(Node root in treeView.Nodes)<br />
{<br />
CheckID(root);<br />
}<br />
<br />
private void CheckID(TreeNode root)<br />
{<br />
Console.WriteLine((Person)root.Tag).ID);<br />
foreach(Node element in root.Nodes)<br />
{<br />
CheckID(element);<br />
}<br />
}<br />
Regards
Senthil
My Blog
|
|
|
|
|
How Can i change a folder's icon using C# as whn i share a folder its icon changes
|
|
|
|