Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2010, 07:45 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default Querying XML data

hi,

i have input data in a xml file as follows

<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee EmployeeId="1" FirstName="Tom" LastName ="Jones">
<Employee EmployeeId="2" FirstName="John" LastName ="Doe">
</Employees>

I appreciate it if you could shed some light on implementing Label1.text= select * where employeeId = somecontrol.selectedvalue.
 
Old January 26th, 2010, 08:22 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Sorry, I don't understand what it is that you are either asking or wanting to achieve.


Can you clarify your question please?

Where is the xml data used? (Dropdownlist, gridview?)

What event needs to take place? (Button click, dropdownlist index change, gridview selection ?)

What do you want to show in the label text and as the suggestion is a SQL command what is the SQL source and what does it contain?
__________________
Try our latest project www.nobanx.com Currency Exchange for members
The Following User Says Thank You to timeware For This Useful Post:
jtnchang (January 26th, 2010)
 
Old January 26th, 2010, 02:50 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Hi, Thanks for your prompt reply.
The xml data is used in two places, namely, in Dropdownlist first and then also in a Label or similar.

What event needs to take place is dropdownlist index change.

I understand that SQL command object is great for showing data in the label. The dropdownlist includes hotelId as SelectedValue and name as SelectedItem. I am desperate of way to my source XML input into a .NET dataset where query can be run against it to return data based on hotelId which comes from the dropdown SelectedValue. The source xml looks massive but I only need hotelId, name, address1, shortdeiscription and RateInfo. The XML looks like the following

<HotelAvailabilityListResults size="5">
<Hotel>
<hotelId>109277</hotelId>
<name>Park Central New York Hotel</name>
<address1>870 7th Ave</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>299.0</lowRate>
<highRate>399.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76452</latitude>
<longitude>-73.98078</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;Park Central New York Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/OM_PARKC-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>CARNEGIE HALL - ACROSS THE ST.</location>
<propertyRating>3.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>4164</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Superior 1 King - Non Smoking</roomDescription>
<roomTypeCode>476</roomTypeCode>
<rateCode>476</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>112922</hotelId>
<name>Hilton New York</name>
<address1>1335 Avenue Of The Americas</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>329.0</lowRate>
<highRate>329.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76225</latitude>
<longitude>-73.97874</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt; The Hilton New York is located in Midtown New York, N.Y., across the street from the Museum of Modern Art and the American Folk Art Museum.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_HILT-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>MOMA - ACROSS THE STREET</location>
<propertyRating>3.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>2</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>P</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>19768</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard Queen-Non Refundable</roomDescription>
<roomTypeCode>45117</roomTypeCode>
<rateCode>172199</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>329.0</displayNightlyRate>
<displayNightlyRate>329.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>781.42</displayRoomRate>
<chargeableRoomRateTotal>781.42</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>123.42</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>329.0</nativeNightlyRate>
<nativeNightlyRate>329.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>781.42</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>140893</hotelId>
<name>The Belvedere Hotel</name>
<address1>319 W 48th St</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10036</postalCode>
<airportCode>NYC</airportCode>
<lowRate>293.33</lowRate>
<highRate>398.67</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76129</latitude>
<longitude>-73.98751</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Belvedere Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_BELV-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>ROCKEFELLER CENTER 3 BLOCKS</location>
<propertyRating>3.0</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>4</currentAllotment>
<propertyId>104193</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Deluxe King</roomDescription>
<roomTypeCode>97306</roomTypeCode>
<rateCode>221517</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>398.67</displayNightlyRate>
<displayNightlyRate>293.33</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>818.33</displayRoomRate>
<chargeableRoomRateTotal>818.33</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>126.33</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>398.67</nativeNightlyRate>
<nativeNightlyRate>293.33</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>818.33</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>112522</hotelId>
<name>Wellington Hotel</name>
<address1>871 7th Ave</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>239.2</lowRate>
<highRate>399.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76446</latitude>
<longitude>-73.98082</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Wellington Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NC_WELLI-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>THEATER DISTRICT MIDTOWN</location>
<propertyRating>3.0</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription>Best Price</promoDescription>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>25888</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard room with double bed</roomDescription>
<roomTypeCode>5662</roomTypeCode>
<rateCode>5662</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>799.7</displayRoomRate>
<chargeableRoomRateTotal>799.7</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>101.7</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>799.7</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>319.2</displayNightlyRate>
<displayNightlyRate>239.2</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>660.1</displayRoomRate>
<chargeableRoomRateTotal>660.1</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>101.7</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>319.2</nativeNightlyRate>
<nativeNightlyRate>239.2</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>660.1</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>111484</hotelId>
<name>Salisbury Hotel</name>
<address1>123 W 57th St</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>223.2</lowRate>
<highRate>299.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76462</latitude>
<longitude>-73.97782</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Salisbury Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_SALI-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>CARNEGIE HALL</location>
<propertyRating>2.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription>Stay 2 nights and save 20% off your stay!</promoDescription>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>25906</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard Room</roomDescription>
<roomTypeCode>2612</roomTypeCode>
<rateCode>2612</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>299.0</displayNightlyRate>
<displayNightlyRate>279.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>666.05</displayRoomRate>
<chargeableRoomRateTotal>666.05</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>299.0</nativeNightlyRate>
<nativeNightlyRate>279.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>666.05</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>239.2</displayNightlyRate>
<displayNightlyRate>223.2</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>550.45</displayRoomRate>
<chargeableRoomRateTotal>550.45</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>239.2</nativeNightlyRate>
<nativeNightlyRate>223.2</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>550.45</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<moreResultsAvailable>true</moreResultsAvailable>
<cacheKey>ab876b3:12458612a38:12ee</cacheKey>
<cacheLocation>10.186.168.48:7301</cacheLocation>
<numberOfRoomsRequested>1</numberOfRoomsRequested>
</HotelAvailabilityListResults>
 
Old January 26th, 2010, 05:14 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Didn't we answer this in displaying dropdown selected value other fields ?

However a quick google displays some XML Select tutorials.

How it works I can't say as I have never tried it, I always pull data from a database (SQL Server usually) and (although i may be limitiing myself) only use XML for RSS feeds, or data imports.


Where are you getting your origina data from? Is it originally in a SQL server database that you have access to, if so we can help you.
__________________
Try our latest project www.nobanx.com Currency Exchange for members
The Following User Says Thank You to timeware For This Useful Post:
jtnchang (January 26th, 2010)
 
Old January 26th, 2010, 07:40 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Thanks Timeware. No SQL Server but a XML file here. I don't know enough about XSLT so I am fumbling between different ideas. The requirment is for one XSL file and one ASPX file so I just googled for XML select for single node and I think I might've gone down the wrong path. I
think XSLT can do the match for Dropdownlist1.SelectedValue and return TEXT vs. XML or ATTRIBUTES. So on ASP.NET side I will just do a Label1.text=IO.read(textfile). Does it sound more like it to you. Thanks.
 
Old January 26th, 2010, 07:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Wink

Hi All,
I tend to use Linq over xpath these days.
Here is a routine I use to get config values from an xml file.
It could easily be modified to get a set of data instead.
Linq appears cleaner to me than XPath.

Code:

publicstaticstring GetConfigurationValue(string configName)
{
string value = string.Empty;
string pathInfo = HttpContext.Current.Server.MapPath("/Configuration.xml.config");
XElement xelement2 = XElement.Load(pathInfo);
try
{
value = (from items in xelement2.Descendants()
where
(string)items.Parent.Attribute("http_host") == HttpHost.Replace("www.", "")
&& (string)items.Attribute("key") == configName
select items).First().Attribute("value").Value;
}
catch
{
value = GetSetting(configName);
}
return value;
}
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old January 26th, 2010, 08:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

EG.
Something like below, but this is not tested in any way.
Code:
var list = (from items in xelement2.Descendants()
where
(string)items.Parent.Attribute("http_host") == "Hotel"
select new HotelData
{
hotelID = items.Attribute("hotelId").Value,
name = items.Attribute("name").Value,
address1 = items.Attribute("address1 ").Value,
shortdeiscription = items.Attribute("shortdeiscription ").Value,
RateInfo = items.Attribute("RateInfo ").Value
}
);
publicclassHotelData{
publicstring hotelID {get;set;}
publicstring name {get;set;}
publicstring address1 {get;set;}
publicstring shortdeiscription {get;set;}
publicstring RateInfo {get;set;}
}
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
The Following User Says Thank You to rodmcleay For This Useful Post:
jtnchang (January 26th, 2010)
 
Old January 26th, 2010, 08:39 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

I have not tried it but I think you got one way that I can tackle now. I was thinking that I had to let XSLT do the querying and then dump it as a text file for ASP.NET to populate into my Label1. Thanks Rodmcleay and much appreciation to Timeware for his dedicated efforts and his ASP.NET expertise. Thanks you both.
 
Old January 29th, 2010, 07:14 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Rodmcleay,

Sorry but I did not find a good Linq to xml sample code and was wondering if you know a link or can be a little more specific on the plumbing code. btw, I use both a XSLT and a XML file and wonder if I have to save the XSL output as a XML file for LINQ to work. Thanks.

Timeware and all,

since I have my xmldatasource based on both a xml file and a xsl stylesheet and it holds the entire dataset. The only thing I am missing is a way to filter it by dropdownlist1.SelectedValue so I can obtain a subset of that data instead of the entire dataset. I can't find a data control that would do that except using xpath(which I hate to pick up on) for filtering. I would appreciate it if someone can shed some light on this seemingly small feat. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
Filtering XML data based on differnt XML ahmed123 XSLT 5 August 11th, 2006 09:15 AM
Problem with repeat data in XML to XML transformat tslag XSLT 4 June 13th, 2006 08:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.