|
See: [^], and [^].
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hi, Can someone help me parse the following XML with DotNet C# 4.0? I'm trying to do it with linq.
XML is as follows...
<?xml version="1.0" encoding="utf-8"?>
<result>
<USEROUT filename="Complete.csv">
<row>
<Error>0</Error>
<Description>"Success"</Description>
<Details>"(Job 1) No Errors detected"</Details>
</row>
<row>
<Error>0</Error>
<Description>"Success"</Description>
<Details>"(Job 2) Scheduling Complete. All available orders were planned."</Details>
</row>
</USEROUT>
<USEROUT filename="User_out.csv">
<row>
<ORDER>""</ORDER>
<CUST_NAME>"A24"</CUST_NAME>
<ADDRESS_1>""</ADDRESS_1>
<ADDRESS_2>""</ADDRESS_2>
<ADDRESS_3>""</ADDRESS_3>
<ADDRESS_4>""</ADDRESS_4>
<ZIPCODE>"XXX"</ZIPCODE>
<ROUTENAME>"Run-0001"</ROUTENAME>
<SEQUENCE>1</SEQUENCE>
<CALLTYPE>4</CALLTYPE>
<TASK_TYPE>0</TASK_TYPE>
<UNIT_1>0.00000</UNIT_1>
<UNIT_2>0.00000</UNIT_2>
<CUST_INFO1>""</CUST_INFO1>
<CUST_INFO2>""</CUST_INFO2>
<CUST_INFO3>""</CUST_INFO3>
<CUST_INFO4>""</CUST_INFO4>
<CUST_INFO5>""</CUST_INFO5>
<LATITUDE>0.00</LATITUDE>
<LONGITUDE>0.00</LONGITUDE>
<LOCATION>"XXX"</LOCATION>
<OPEN1>"00:00:00"</OPEN1>
<CLOSE1>"00:00:00"</CLOSE1>
<OPEN2>"00:00:00"</OPEN2>
<CLOSE2>"00:00:00"</CLOSE2>
<PROD_A>0</PROD_A>
<PROD_B>0</PROD_B>
<PROD_C>0</PROD_C>
<PROD_D>0</PROD_D>
<PROD_E>0</PROD_E>
<ARR_DAY>"Mon"</ARR_DAY>
<ARR_TIME>"19:00:00"</ARR_TIME>
<DEP_DAY>"Mon"</DEP_DAY>
<DEP_TIME>"19:00:00"</DEP_TIME>
<DURATION>0</DURATION>
<TRAV_TIME>0</TRAV_TIME>
<TRAV_DIST>0.000</TRAV_DIST>
<REVENUE>0.0000</REVENUE>
<STATUS>2</STATUS>
<DESCRIP>""</DESCRIP>
<START_DEP>"A24"</START_DEP>
<FINISH_DEP>"A24"</FINISH_DEP>
<TOT_DIST>61.000</TOT_DIST>
<TOT_TIME>102</TOT_TIME>
<TOT_DUTY>102</TOT_DUTY>
<VEHICLE_NAME>"PDA3"</VEHICLE_NAME>
</row>
<row>
<ORDER>"761"</ORDER>
<CUST_NAME>"YYY"</CUST_NAME>
<ADDRESS_1>"111"</ADDRESS_1>
<ADDRESS_2>"222"</ADDRESS_2>
<ADDRESS_3>"0.00"</ADDRESS_3>
<ADDRESS_4>"0.00"</ADDRESS_4>
<ZIPCODE>"XXX"</ZIPCODE>
<ROUTENAME>"Run-0001"</ROUTENAME>
<SEQUENCE>2</SEQUENCE>
<CALLTYPE>2</CALLTYPE>
<TASK_TYPE>2</TASK_TYPE>
<UNIT_1>0.00000</UNIT_1>
<UNIT_2>0.00000</UNIT_2>
<CUST_INFO1>""</CUST_INFO1>
<CUST_INFO2>""</CUST_INFO2>
<CUST_INFO3>""</CUST_INFO3>
<CUST_INFO4>""</CUST_INFO4>
<CUST_INFO5>""</CUST_INFO5>
<LATITUDE>0.00</LATITUDE>
<LONGITUDE>0.00</LONGITUDE>
<LOCATION>"XXX"</LOCATION>
<OPEN1>"19:00:00"</OPEN1>
<CLOSE1>"07:00:00"</CLOSE1>
<OPEN2>"00:00:00"</OPEN2>
<CLOSE2>"00:00:00"</CLOSE2>
<PROD_A>0</PROD_A>
<PROD_B>0</PROD_B>
<PROD_C>0</PROD_C>
<PROD_D>0</PROD_D>
<PROD_E>0</PROD_E>
<ARR_DAY>"Mon"</ARR_DAY>
<ARR_TIME>"19:16:00"</ARR_TIME>
<DEP_DAY>"Mon"</DEP_DAY>
<DEP_TIME>"19:25:00"</DEP_TIME>
<DURATION>9</DURATION>
<TRAV_TIME>16</TRAV_TIME>
<TRAV_DIST>6.000</TRAV_DIST>
<REVENUE>0.0000</REVENUE>
<STATUS>2</STATUS>
<DESCRIP>""</DESCRIP>
<START_DEP>"A24"</START_DEP>
<FINISH_DEP>"A24"</FINISH_DEP>
<TOT_DIST>61.000</TOT_DIST>
<TOT_TIME>102</TOT_TIME>
<TOT_DUTY>102</TOT_DUTY>
<VEHICLE_NAME>"PDA3"</VEHICLE_NAME>
</row>
<row>
<ORDER>"762"</ORDER>
<CUST_NAME>"111"</CUST_NAME>
<ADDRESS_1>"222"</ADDRESS_1>
<ADDRESS_2>"333"</ADDRESS_2>
<ADDRESS_3>"0.00"</ADDRESS_3>
<ADDRESS_4>"0.00"</ADDRESS_4>
<ZIPCODE>"XXX"</ZIPCODE>
<ROUTENAME>"Run-0001"</ROUTENAME>
<SEQUENCE>3</SEQUENCE>
<CALLTYPE>2</CALLTYPE>
<TASK_TYPE>2</TASK_TYPE>
<UNIT_1>0.00000</UNIT_1>
<UNIT_2>0.00000</UNIT_2>
<CUST_INFO1>""</CUST_INFO1>
<CUST_INFO2>""</CUST_INFO2>
<CUST_INFO3>""</CUST_INFO3>
<CUST_INFO4>""</CUST_INFO4>
<CUST_INFO5>""</CUST_INFO5>
<LATITUDE>0.00</LATITUDE>
<LONGITUDE>0.00</LONGITUDE>
<LOCATION>"XXX"</LOCATION>
<OPEN1>"19:00:00"</OPEN1>
<CLOSE1>"07:00:00"</CLOSE1>
<OPEN2>"00:00:00"</OPEN2>
<CLOSE2>"00:00:00"</CLOSE2>
<PROD_A>0</PROD_A>
<PROD_B>0</PROD_B>
<PROD_C>0</PROD_C>
<PROD_D>0</PROD_D>
<PROD_E>0</PROD_E>
<ARR_DAY>"Mon"</ARR_DAY>
<ARR_TIME>"19:51:00"</ARR_TIME>
<DEP_DAY>"Mon"</DEP_DAY>
<DEP_TIME>"20:00:00"</DEP_TIME>
<DURATION>9</DURATION>
<TRAV_TIME>26</TRAV_TIME>
<TRAV_DIST>24.000</TRAV_DIST>
<REVENUE>0.0000</REVENUE>
<STATUS>2</STATUS>
<DESCRIP>""</DESCRIP>
<START_DEP>"A24"</START_DEP>
<FINISH_DEP>"A24"</FINISH_DEP>
<TOT_DIST>61.000</TOT_DIST>
<TOT_TIME>102</TOT_TIME>
<TOT_DUTY>102</TOT_DUTY>
<VEHICLE_NAME>"PDA3"</VEHICLE_NAME>
</row>
<row>
<ORDER>"764"</ORDER>
<CUST_NAME>"ZZZZ"</CUST_NAME>
<ADDRESS_1>"111"</ADDRESS_1>
<ADDRESS_2>"222"</ADDRESS_2>
<ADDRESS_3>"333"</ADDRESS_3>
<ADDRESS_4>"444"</ADDRESS_4>
<ZIPCODE>"XXX"</ZIPCODE>
<ROUTENAME>"Run-0001"</ROUTENAME>
<SEQUENCE>4</SEQUENCE>
<CALLTYPE>2</CALLTYPE>
<TASK_TYPE>2</TASK_TYPE>
<UNIT_1>0.00000</UNIT_1>
<UNIT_2>0.00000</UNIT_2>
<CUST_INFO1>""</CUST_INFO1>
<CUST_INFO2>""</CUST_INFO2>
<CUST_INFO3>""</CUST_INFO3>
<CUST_INFO4>""</CUST_INFO4>
<CUST_INFO5>""</CUST_INFO5>
<LATITUDE>0.00</LATITUDE>
<LONGITUDE>0.00</LONGITUDE>
<LOCATION>"XXX"</LOCATION>
<OPEN1>"19:00:00"</OPEN1>
<CLOSE1>"07:00:00"</CLOSE1>
<OPEN2>"00:00:00"</OPEN2>
<CLOSE2>"00:00:00"</CLOSE2>
<PROD_A>0</PROD_A>
<PROD_B>0</PROD_B>
<PROD_C>0</PROD_C>
<PROD_D>0</PROD_D>
<PROD_E>0</PROD_E>
<ARR_DAY>"Mon"</ARR_DAY>
<ARR_TIME>"20:01:00"</ARR_TIME>
<DEP_DAY>"Mon"</DEP_DAY>
<DEP_TIME>"20:10:00"</DEP_TIME>
<DURATION>9</DURATION>
<TRAV_TIME>1</TRAV_TIME>
<TRAV_DIST>0.000</TRAV_DIST>
<REVENUE>0.0000</REVENUE>
<STATUS>2</STATUS>
<DESCRIP>""</DESCRIP>
<START_DEP>"A24"</START_DEP>
<FINISH_DEP>"A24"</FINISH_DEP>
<TOT_DIST>61.000</TOT_DIST>
<TOT_TIME>102</TOT_TIME>
<TOT_DUTY>102</TOT_DUTY>
<VEHICLE_NAME>"PDA3"</VEHICLE_NAME>
</row>
<row>
<ORDER>""</ORDER>
<CUST_NAME>"A24"</CUST_NAME>
<ADDRESS_1>""</ADDRESS_1>
<ADDRESS_2>""</ADDRESS_2>
<ADDRESS_3>""</ADDRESS_3>
<ADDRESS_4>""</ADDRESS_4>
<ZIPCODE>"XXX"</ZIPCODE>
<ROUTENAME>"Run-0001"</ROUTENAME>
<SEQUENCE>5</SEQUENCE>
<CALLTYPE>4</CALLTYPE>
<TASK_TYPE>0</TASK_TYPE>
<UNIT_1>0.00000</UNIT_1>
<UNIT_2>0.00000</UNIT_2>
<CUST_INFO1>""</CUST_INFO1>
<CUST_INFO2>""</CUST_INFO2>
<CUST_INFO3>""</CUST_INFO3>
<CUST_INFO4>""</CUST_INFO4>
<CUST_INFO5>""</CUST_INFO5>
<LATITUDE>0.00</LATITUDE>
<LONGITUDE>0.00</LONGITUDE>
<LOCATION>"XXX"</LOCATION>
<OPEN1>"00:00:00"</OPEN1>
<CLOSE1>"00:00:00"</CLOSE1>
<OPEN2>"00:00:00"</OPEN2>
<CLOSE2>"00:00:00"</CLOSE2>
<PROD_A>0</PROD_A>
<PROD_B>0</PROD_B>
<PROD_C>0</PROD_C>
<PROD_D>0</PROD_D>
<PROD_E>0</PROD_E>
<ARR_DAY>"Mon"</ARR_DAY>
<ARR_TIME>"20:42:00"</ARR_TIME>
<DEP_DAY>"Mon"</DEP_DAY>
<DEP_TIME>"20:42:00"</DEP_TIME>
<DURATION>0</DURATION>
<TRAV_TIME>31</TRAV_TIME>
<TRAV_DIST>29.000</TRAV_DIST>
<REVENUE>0.0000</REVENUE>
<STATUS>2</STATUS>
<DESCRIP>""</DESCRIP>
<START_DEP>"A24"</START_DEP>
<FINISH_DEP>"A24"</FINISH_DEP>
<TOT_DIST>61.000</TOT_DIST>
<TOT_TIME>102</TOT_TIME>
<TOT_DUTY>102</TOT_DUTY>
<VEHICLE_NAME>"PDA3"</VEHICLE_NAME>
</row>
</USEROUT>
</result>
I have a class as follows for the results...
public class Callout
{
public string CalloutID { get; set; }
public string TaskType { get; set; }
public string ArrDay { get; set; }
public string ArrTime { get; set; }
public string VehicleName { get; set; }
public string Sequence { get; set; }
}
My code I am using is as follows...
Stream ReceiveStream = myWebResponse.GetResponseStream();
StreamReader readStream = new StreamReader(ReceiveStream);
string responseString = readStream.ReadToEnd();
List<Callout> jobList =
(
from item in XDocument.Parse(responseString).Elements("row")
select new Callout
{
CalloutID = (string)item.Element("ORDER"),
TaskType = (string)item.Element("TASK_TYPE"),
ArrDay = (string)item.Element("ARR_DAY"),
ArrTime = (string)item.Element("ARR_TIME"),
VehicleName = (string)item.Element("VEHICLE_NAME"),
Sequence = (string)item.Element("SEQUENCE")
}).ToList();
My code doesn't throw any errors, the string variable responseString holds the XML correctly, but nothing goes into the jobList from the Linq query.
Where am I going wrong?
Many thanks.
|
|
|
|
|
You're calling .Elements("row") on the XDocument instance. The document only contains a single element, which is the root element of the XML document.
You'll need to use the Descendants method to find the rows. You'll also need to restrict the scope to the relevant USEROUT node, since the row elements under the first node don't match your expected layout.
List<Callout> jobList = XDocument.Parse(responseString)
.Descendants("USEROUT")
.Where(el => string.Equals((string)el.Attribute("filename"), "User_out.csv", StringComparison.OrdinalIgnoreCase))
.Descendants("row")
.Select(item => new Callout { ... })
.ToList();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard, Firstly, thanks for taking the time to respond.
You answer was exactly what I needed - many thanks for this.
One quick question... Is it possible to add some sort of where clause into it so that only those rows with a TASK_TYPE = "2" are returned? Sorry, I'm new to parsing XML...
|
|
|
|
|
Something like this should do the trick:
List<Callout> jobList = XDocument.Parse(responseString)
.Descendants("USEROUT")
.Where(el => string.Equals((string)el.Attribute("filename"), "User_out.csv", StringComparison.OrdinalIgnoreCase))
.Descendants("row")
.Where(item => string.Equals((string)item.Attribute("TASK_TYPE"), "2", StringComparison.Ordinal))
.Select(item => new Callout { ... })
.ToList();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hello. I need help in getting site ID and Status on IIS7 using Web Administration. I have this code
private string getSiteIdByName(string siteName)
{
DirectoryEntry root = getDirectoryEntry("IIS://" + textServer.Text + "/W3SVC");
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IIsWebServer")
{
if (e.Properties["ServerComment"].Value.ToString().Equals(siteName, StringComparison.OrdinalIgnoreCase))
{
return e.Name;
}
}
}
return null;
}
private void showStatus(string siteId)
{
string result = "unknown";
DirectoryEntry root = getDirectoryEntry("IIS://" + textServer.Text + "/W3SVC/" + siteId);
PropertyValueCollection pvc;
pvc = root.Properties["ServerState"];
if (pvc.Value != null)
result = (pvc.Value.Equals((int)ObjectState.Start) ? "Running" :
pvc.Value.Equals((int)ObjectState.Stop) ? "Stopped" :
pvc.Value.Equals((int)ObjectState.Pause) ? "Paused" :
pvc.Value.ToString());
labelStatus.Text = result + " (" + pvc.Value + ")";
}
but it really doesn't work well with some of our servers. Is there a way to use Web Administration for this? Any assistance is greatly appreciated.
Thanks!
|
|
|
|
|
Sir / Madam,
How to access .chm file present in zip file without extracting it ?
There are many .chm files used as resource in my windows application hence finding a way to do it without extracting them for saving disk space.
|
|
|
|
|
.chm themselves can be compressed by LZX[^], therefore I don't see a need to pack them in a zip-File. Another way of lowering the disk space needed by your .chm files is to lower the resolution of the images in them, if there are any.
Zip-File are Archives, and since they are compressed they don't offer the full functionality of a normal folder to access its contents, leading to problems as you scripted (No, you can't access .chm files stored in a Zip-Archive).
People becoming wiser in order to notice the stupid things they did back in the young days. This doesn't mean that they really stop doing those things. Wise people still do stupid things, only on purpose.
|
|
|
|
|
There are many .chm files in my windows application hence I have grouped them and zipped them separately.
Can you suggest any other way of doing this...
Thank you for the reply....
|
|
|
|
|
Extract/unzip the CHM (to a temp folder) when the user wants to view it, remove again when done.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Ok, I have implemented the same procedure told by Eddy. But I was searching for the another possible ways for doing it...
Thank you for replying Eddy and Marco....
|
|
|
|
|
Pratik_P wrote: Ok, I have implemented the same procedure told by Eddy. But I was searching for the another possible ways for doing it...
No need to worry, sometimes the easy way is better hand the hard way.
Pratik_P wrote: Thank you for replying Eddy and Marco....
You are welcome, glad that we were able to help you.
People becoming wiser in order to notice the stupid things they did back in the young days. This doesn't mean that they really stop doing those things. Wise people still do stupid things, only on purpose.
|
|
|
|
|
I need to save and restore printer settings that are kept in the devmode structure. I found an article here that helped get me that far.
I am concerned at what might happen if the printer's driver is updated. I saw it mentioned here or elsewhere that attempting to load the devmode might do terrible things if we attempted to save the devmode then load it under a different operating system. Presumably changing the driver version might have similar effect.
I was hoping to programatically verify that the operating system and print driver had not changed in order to prevent disasters. Thing is, I haven't seen even a hint of how to identify the printer driver version.
|
|
|
|
|
Hi,
I am building an entire survey dynamically. I just have a panel defined on the page, and adding controls dynamically to this panel to render my page. The survey question and answers are all stored in the database. So, i have built controls for textbox areas, checkboxlist.
I am kind of stumped on the radiobuttonlist control. It is not working on the ID part. I have defined a radiobuttonlist, and adding this list. If I define the ID outside the for loop, on submitting the code fails on "Multiple controls with the same rdb value. And if I add it inside the for loop, you are to select multiple radio buttons, which is not right.
Any ideas?? Thanks!
RadioButtonList rbL = new RadioButtonList();
rbL.ID = "rdb_";
foreach (string s in eachQ[i].answer.Split(','))
{
rbL.Items.Add(new ListItem(s));
rbL.ID = "rdb_" + eachQ[i].answerid.ToString();
pnlQuestions.Controls.Add(rbL);
}
|
|
|
|
|
Try something like:
var rbl = new RadioButtonList();
rbl.ID = "rdb_" + eachQ[i].answerid;
var options = eachQ[i].answer.Split(',');
for (int optionIndex = 0; optionIndex < options.Length; optionIndex++)
{
rbl.Items.Add(new ListItem(options[optionIndex], optionIndex.ToString()));
}
pnlQuestions.Controls.Add(rbl);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
RadioButtonList rbL = new RadioButtonList();
is above line in any other loop ?
If yes then update your question with that code as well.
Regards,
CodeBlack
|
|
|
|
|
You probably know this - a group of radio boxes need to be within a panel or group control
in order to 'group' them together so that they act in unison.
If you are placing a large number of radioboxes within one panel their behaviour will be unpredictable.
For instance an 'on/off' radio selection need to being their own panel or group in order to act exclusively on each other.
You probably know all the above.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hello ,
Am a c# beginner and currently able to bind data from mysql to a C# DataViewGrid through dataTable and dataAdapters . I'm Wondering ,is there a way of mapping the same column by column to a DataviewGrid with already constructed columns like i do in Delphi&XstringGrid ..code snippet below......
sqlstr:=' select rno,rdate,accountof,tenant,building,receivedfrom,account,amount,posted,approved,crct from receipts where reversed <> 9 and ';
i:=1;
xs.RowCount := recordcount + 2;
while not eof do begin
xs.cells[0,i] := fieldbyname('rno').asstring;
xs.cells[1,i] := fieldbyname('accountof').asstring;
xs.cells[2,i] := fieldbyname('rdate').asstring;
xs.cells[3,i] := fieldbyname('tenant').asstring;
xs.cells[4,i] := fieldbyname('receivedfrom').asstring;
xs.cells[5,i] := fieldbyname('building').asstring;
xs.cells[6,i] := fieldbyname('account').asstring;
xs.cells[7,i] := fieldbyname('amount').asstring;
if fieldbyname('posted').asinteger = 0 then xs.cells[8,i] := 'No' else xs.cells[8,i] := 'Yes';
xs.cells[9,i] := fieldbyname('accountof').asstring;
xs.cells[12,i] := fieldbyname('crct').asstring;
building := fieldbyname('building').asstring;
if fieldbyname('approved').asinteger = 0 then xs.cells[13,i] := 'No' else xs.cells[13,i] := 'Yes';
next;Inc(i,1);
end;
end;
end;
|
|
|
|
|
|
Hello. I have taken backup of MySql database using MySqlDump and it is named as MyBackup.Sql (SchemaName = TestSchema, TableName = TestTable). Now let us suppose I don't have MySql Workbench so I can not examine this database using Data Import.
Now how do I add/update/delete records using this .sql file? I don't know what the connection string will look like and all the related stuff. Thanks for any input.
|
|
|
|
|
Django_Untaken wrote: Now how do I add/update/delete records using this .sql file? You can't; a backup of a database does not offer the same functionality as a database.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Then how will I deploy the database with my .exe? I want this database (along with my .exe project) to be available on other computer where there is no visual studio, no sql server or no mysql workbench?
|
|
|
|
|
If you don't have SQL or MySql installed and available, then your backup is completely useless.
If you are looking at a single user for the database, then consider changing to SQLite or SQLCE, or even Access, none of which require a dedicated server application to use a database - just a couple of DLL files which can be distributed with your application.
The only instant messaging I do involves my middle finger.
English doesn't borrow from other languages.
English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.
|
|
|
|