|
|
Instead of keeping track of an int that's the index into the ArrayList , just keep track of the object (presumably a User ) that you added to the ArrayList . That way you can check if the user is still connected by using Contains() rather than accessing an index that may be invalid.
/ravi
|
|
|
|
|
Oh... So like, assign a user some kind of unique ID or something and pass that to my overridden Contains() ? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Yes, that will definitely work and is a common way of checking for the presence of objects.
/ravi
|
|
|
|
|
OK, thanks very much!
Windows Calculator told me I will die at 28.
|
|
|
|
|
I looked all over the web for an easy way to read an XML file, with no success. Most places I found used the XmlTextReader.Read() method, which I don't find easy to use if I dont wanna go thru the whole file.
This is what I am looking for. Say I have the following XML file:
<city name="New York">
<population>10,000,000</population>
<growth>1.2</growth>
</city>
<city name="Miami">
<population>7,000,000</population>
<growth>2.4</growth>
</city>
and I would like to access Miami's population element (and get the 7,000,000 string) something like this (I have invent the names of the methods - the final question follows these exampls):
string PopulationOfMiami = xmlfile["Miami"].population;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].population.value;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].ElementSon("population").value;
or perhaps:
string PopulationOfMiami = xmlfile.findNameAttribute("Miami").population.value;
I want access to my XML file in a similar form in one of the above fashioned-way. Does anyone know of real methods and class that work like above? I hope I explained myself OK .
Thanks,
Yoni
|
|
|
|
|
|
It looks like you should actually be using XmlDocument, rather than XmlTextReader. That will let you access your data similar to what you're looking for.
XmlDocument doc = new XmlDocument();
doc.LoadXml(yourXML);
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
Alternately, you can create an XML serializer, which would give you syntax closer to what you're looking for.
--------------
TTFN - Kent
|
|
|
|
|
Thanks - this looks like what I was looking for. Problem is that I have a problem:
My XML is a file, not a string variable. i.e. this doesn't work:
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"c:\myfile.xml");
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
I looked around for a way around this, trying to give LoadXml a XmlReader and XmlTextReader, but nothing. How can I load my XML file and then do the select?
Thanks,
Yoni
|
|
|
|
|
If the XML is in a file use doc.Load(path) instead.
--------------
TTFN - Kent
|
|
|
|
|
Thanks. New problem
I get a "XmlException: '?' is an unexpected token. Expecting white space" exception. doh. Any ideas?
Thanks again,
Yoni
|
|
|
|
|
What does your XML look like?
-- modified at 14:52 Tuesday 12th December, 2006
As in, it's not just the six lines above, is it?
--------------
TTFN - Kent
|
|
|
|
|
No, it isn't just six lines. It's similar tho - many more cities and many more elements. Now that you mention it - it has a first line:
<?xml version="1.0" encoding="ISO-8859-1"?>
Could it be this?
-- modified at 21:29 Tuesday 12th December, 2006
|
|
|
|
|
No, that's a fairly standard XML declaration. However, I'm guessing there's some high-ASCII character somewhere in that document, or something sitting in the wrong place. Does the error message come with a position (something along the lines of "The expected token is 'whitespace'. Line 1, position 40. )
--------------
TTFN - Kent
|
|
|
|
|
ahhh Thanks! Indeed - it did have a position - I looked it up in the XML and found a name with a quote in it I'll escape it.
Many thanks,
Yoni
|
|
|
|
|
Hi,
There is another way which you can read the values of XML file. Given below the code.
1. In the XML file, add the lines as below:
CityNY name="New York" population=10,000,000 growth=1.2
CityMi name="Miami" population=7,000,000 growth=2.4
2. Open a new class called ReadXMLConfig
3. use the namespace, using System.Xml;
4. Declare the data members as follows :
public class ReadXMLConfig
{
XMLDocument xmlDoc;
private string NYName;
private string NYpop;
private string NYgrowth;
private string MiName;
private string Mipop;
private string Migrowth;
}
5. Type the following in the constructor area:
xmlDoc=new XmlDocument // in the constructor
NYName = null;
NYpop = null;
NYgrowth = null;
MiName=null;
Mipop=null;
migrowth=null;
6. Create a function called LoadXML and type as follows:
public void LoadXML()
{
xmlDoc.Load("XMLFilename");
XmlNodeList elemList;
XmlElement elem;
elemList = xmlDoc.GetElementsByTagName("CityNY");
elem = (XmlElement)elemList[0];
NYName = elem.GetAttribute("name");
NYpop = elem.GetAttribute("population");
NYgrowth = elem.GetAttribte("growth");
elemList = xmlDoc.GetElementsByTagName("CityMi");
elem = (XmlElement)elemList[0];
MiName = elem.GetAttribute("name");
Mipop = elem.GetAttribute("population");
Migrowth = elem.GetAttribte("growth");
}
Call this load function wherever you want.
Hope this will helps.
Cheers
-- modified at 4:24 Tuesday 12th December, 2006
Meeram395
|
|
|
|
|
Thanks, but I can't change the XML so easily - I found a VB code on the net that converts an excel file to an xml file. It isn't flexible. the city tags represent a row in an excel. can't rename them.
Thanks anyway, I might use this in the future.
Yoni
|
|
|
|
|
I have a function that takes a string in html format and print it ona printer in my small windows c# program. I am wondering how can i add print preview functionality to this. I have no clue.
To print a richTextbox i just used like that, but this is a webbroweser control.
thanks
printpreivewDialog pp = new printpreivewDialog();
pp.document=doc;
pp.ShowDialog();
public void PrintHtml(string sHtml,bool bPromt)
{
frmObj.axD.DocumentHTML=sHtml;
for(;frmObj.axD.Busy!=false;)
{
System.Windows.Forms.Application.DoEvents();
}
object opt=null;
if (bPromt)
opt="1";
frmObj.axD.PrintDocument(ref opt);
}
|
|
|
|
|
We are trying to deploy with ClickOnce approach. We use msbuild.exe to generate the Deliverables, so basically user can have two entry points: the .application file And the setup.exe.
Here the HTML file.
Ref 1:
<title>Start
function getStartFile()
{
if ((navigator.userAgent.indexOf("NET CLR 2")>-1))
{
document.write('<a href=./Publish/Start.OperationDialogs.application>Start</a>');
}
else
{
document.write('<a href=./Publish/setup.exe>Start</a>');
}
}
getStartFile();
(If no .Net 2.0 is installed, then use setup.exe to install and then launch application. If already installed .Net 2.0, just use Start.Moderators.application to launch application.)
Because our product will be deployed at multiple Websites, our concerns is whether the Deliverable can "self-update" its deployUrl and updateUrl in .application file and .dlls.
Which means, we just msbuild.exe for one time, then the deliverable can be put anywhere.
Our application is deployed at Linux OS and Resin Server. So we can not run mage through Asp.net.
So, is there something we can do to achieve it? like jsp, servlet?
Thank you!
|
|
|
|
|
I'm not sure if there is a quick and dirty way to do what I want to do, but I figured i would throw the question out.
Basically I am reading data from a serial port and using the Read method to read data into a byte buffer. I have to get the data that is stored in the byte buffer into an UInt16 buffer (the first 2 elements of the byte array should be the first element in the UInt16 array, the the next 2 etc.)because that is the message format for my message. Is there a quick way to do this without having to shift and logically and/or each element of the byte array before setting it to the UInt16 array?
so basically:
((byteArray[0] << 8 ) & byteArray[1]) = UInt16Array[0];
((byteArray[2] << 8 ) & byteArray[3]) = UInt16Array[1];
((byteArray[4] << 8 ) & byteArray[5]) = UInt16Array[2];
|
|
|
|
|
No. there isn't. As you are swapping the byte order, you have to do this for each value.
---
b { font-weight: normal; }
|
|
|
|
|
i have project with database Access
i want to make backup every day
now i want to know how to make copy to file ??
just make Copy to File ????
Palestine
|
|
|
|
|
System.IO.File.Copy(cSource,cDest);
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
i have project with database Access
Palestine
|
|
|
|
|
RIGHT ON!
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|