If you use Products_GetLowestOfferListingsForASIN method
http://docs.developer.amazonservices.com/en_US/products/Products_GetLowestOfferListingsForASIN.html
you get 3 offers
<GetLowestOfferListingsForASINResponse
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetLowestOfferListingsForASINResult ASIN="B002KT3XQM" status="Success">
<AllOfferListingsConsidered>true</AllOfferListingsConsidered>
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"
xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>B002KT3XQM</ASIN>
</MarketplaceASIN>
</Identifiers>
<LowestOfferListings>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>Used</ItemCondition>
<ItemSubcondition>VeryGood</ItemSubcondition>
<FulfillmentChannel>Merchant</FulfillmentChannel>
<ShipsDomestically>True</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>762</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>32.99</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>28.00</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>4.99</Amount>
</Shipping>
</Price>
<MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice>
</LowestOfferListing>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>New</ItemCondition>
<ItemSubcondition>New</ItemSubcondition>
<FulfillmentChannel>Amazon</FulfillmentChannel>
<ShipsDomestically>True</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>181744</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>34.27</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>34.27</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
<MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice>
</LowestOfferListing>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>New</ItemCondition>
<ItemSubcondition>New</ItemSubcondition>
<FulfillmentChannel>Amazon</FulfillmentChannel>
<ShipsDomestically>True</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>13213</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>41.18</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>41.18</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
<MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice>
</LowestOfferListing>
</LowestOfferListings>
</Product>
</GetLowestOfferListingsForASINResult>
<ResponseMetadata>
<RequestId>60979901-82af-457b-8bdd-EXAMPLE28478</RequestId>
</ResponseMetadata>
But if I visit product page:
https://www.amazon.com/gp/offer-listing/B002KT3XQM/ref=olp_page_1?ie=UTF8&f_new=true
I see 13 offers.
Is it possible get all 13 offers?
The GetLowestOfferListingsForASIN call gives you one result for each set of so-called "Qualifiers". Your example shows three distinct sets of such Qualifiers:
Used-VeryGood->Merchant->True->0-2 days->90-94% for $32.99 (incl. shippng)
New->New->Amazon->True->0-2 days->98-100% for $34.27
New->New->Amazon->True->0-2 days->95-97% for $41.18
What is puzzling me, is that no new "Merchant" offers were shown, when I really think they should:
New->New->Merchant->True->0-2 days->98-100% would be a distinct fourth set of qualifiers.
What you really seem to be looking for is a different call: GetLowestPricedOffersForASIN returns up to 20 different offers for a single ASIN.
Related
Please Help....
I am rather new to python and cannot find a way to only target the last tag found in the xml document. I am trying to get the last j151 "172.00" tag in the xml.
Code Being Used.
import xml.etree.cElementTree as ET
import pyodbc
import mysql.connector
import os
tree = ET.parse('C:\OnixFile\Pearson_SA_20211027-160725999_onix.xml')
root = tree.getroot()
count = 0
for product in root.findall('product'):
#Variables
SurAndInit = pubType = language = subject = othertext = shortDesc = longDesc = currencyPrice= publisher =""
count = count + 1
for sd in product.findall('supplydetail'):
supplydetail = sd.find('j137').text
for pc in sd.findall('price'):
price = pc.find('j151').text
print(price)
XML being used is below.
<product>
<a001>9780636155343</a001>
<a002>03</a002>
<a194>01</a194>
<a197>jimmy South Africa</a197>
<productidentifier>
<b221>03</b221>
<b244>9780636155343</b244>
</productidentifier>
<productidentifier>
<b221>15</b221>
<b244>9780636155343</b244>
</productidentifier>
<b012>DG</b012>
<b211>029</b211>
<b212>EPUB 2.0.1</b212>
<series>
<title>
<b202>01</b202>
<b203>Today</b203>
</title>
</series>
<title>
<b202>01</b202>
<b203>Life Orientation Today Grade 8 Learner's Book ePUB (perpetual licence)</b203>
</title>
<workidentifier>
<b201>01</b201>
<b233>GCOI</b233>
<b244>20157105570300</b244>
</workidentifier>
<workidentifier>
<b201>15</b201>
<b244>9780636155343</b244>
</workidentifier>
<contributor>
<b034>1</b034>
<b035>A01</b035>
<b036>G Euvrard</b036>
<b037>Euvrard, G</b037>
<b039>G</b039>
<b040>Euvrard</b040>
<personnameidentifier>
<b390>01</b390>
<b233>Onixsuite Contributor ID</b233>
<b244>3108</b244>
</personnameidentifier>
</contributor>
<contributor>
<b034>2</b034>
<b035>A01</b035>
<b036>H Findlay</b036>
<b037>Findlay, H</b037>
<b039>H</b039>
<b040>Findlay</b040>
<personnameidentifier>
<b390>01</b390>
<b233>Onixsuite Contributor ID</b233>
<b244>3109</b244>
</personnameidentifier>
</contributor>
<contributor>
<b034>3</b034>
<b035>A01</b035>
<b036>C Normand</b036>
<b037>Normand, C</b037>
<b039>C</b039>
<b040>Normand</b040>
<personnameidentifier>
<b390>01</b390>
<b233>Onixsuite Contributor ID</b233>
<b244>3110</b244>
</personnameidentifier>
</contributor>
<b057>1</b057>
<language>
<b253>01</b253>
<b252>eng</b252>
</language>
<language>
<b253>02</b253>
<b252>eng</b252>
</language>
<b061>168</b061>
<extent>
<b218>00</b218>
<b219>168</b219>
<b220>03</b220>
</extent>
<b064>FAM000000</b064>
<b065>YQN</b065>
<subject>
<b067>12</b067>
<b069>YQW</b069>
</subject>
<subject>
<b067>12</b067>
<b069>YQX</b069>
</subject>
<audience>
<b204>01</b204>
<b206>04</b206>
</audience>
<audience>
<b204>22</b204>
<b206>00</b206>
</audience>
<audiencerange>
<b074>17</b074>
<b075>03</b075>
<b076>13 T</b076>
<b075>04</b075>
<b076>15</b076>
</audiencerange>
<othertext>
<d102>01</d102>
<d104 language="eng" textformat="02"><strong>T</strong>rust <strong><em>TODAY</em></strong> to be up-to-date and fresh for the classroom.<br> <strong>O</strong>pportunities for revision, exam practice and assessment throughout.<br> <strong>D</strong>evelops language skills alongside subject knowledge.<br> <strong>A</strong>ll content is fully CAPS-compliant.<br> <strong>Y</strong>our easy-to-use complete classroom solution!<br> <strong><em>TODAY</em></strong>, for successful teaching tomorrow.<br><br> This eBook is a digital version of the printed, CAPS-approved book. Benefits of the ePUB formatinclude:<br> <ul> <li>The ability to view on a desktop computer, notebook or tablet;<br> </li> <li>As learners adjust fonts, rotate and flip pages, content reflows to fit the device's screen giving the user a more flexible experience; and<br> </li> <li>Learners can take notes, highlight and bookmark, and access video and audio for visuallearning. </li></ul></d104>
</othertext>
<othertext>
<d102>03</d102>
<d104 language="eng" textformat="02"><strong>T</strong>rust <strong><em>TODAY</em></strong> to be up-to-date and fresh for the classroom.<br> <strong>O</strong>pportunities for revision, exam practice and assessment throughout.<br> <strong>D</strong>evelops language skills alongside subject knowledge.<br> <strong>A</strong>ll content is fully CAPS-compliant.<br> <strong>Y</strong>our easy-to-use complete classroom solution!<br> <strong><em>TODAY</em></strong>, for successful teaching tomorrow.<br><br> This eBook is a digital version of the printed, CAPS-approved book. Benefits of the ePUB formatinclude:<br> <ul> <li>The ability to view on a desktop computer, notebook or tablet;<br> </li> <li>As learners adjust fonts, rotate and flip pages, content reflows to fit the device's screen giving the user a more flexible experience; and<br> </li> <li>Learners can take notes, highlight and bookmark, and access video and audio for visuallearning. </li></ul></d104>
</othertext>
<othertext>
<d102>02</d102>
<d104 language="eng">Trust TODAY to be up-to-date and fresh for the classroom.</d104>
</othertext>
<productwebsite>
<b367>02</b367>
<f123>http://jimmysa.app.onixsuite.com/book/?GCOI=20157105570300</f123>
</productwebsite>
<imprint>
<b079>Maskew Miller Longman</b079>
</imprint>
<publisher>
<b291>01</b291>
<b081>jimmy South Africa</b081>
</publisher>
<b209>Cape Town, South Africa</b209>
<b083>ZA</b083>
<b394>04</b394>
<b003>20140630</b003>
<copyrightstatement>
<b087>2013</b087>
<copyrightowner>
<b047>jimmy South Africa</b047>
</copyrightowner>
</copyrightstatement>
<salesrights>
<b089>01</b089>
<b090>ZA</b090>
</salesrights>
<relatedproduct>
<h208>13</h208>
<productidentifier>
<b221>15</b221>
<b244>9780636115651</b244>
</productidentifier>
</relatedproduct>
<supplydetail>
<j137>jimmy SA</j137>
<j292>01</j292>
<j138>ZA</j138>
<j396>20</j396>
<j143>20140630</j143>
<price>
<j148>01</j148>
<j151>10.72</j151>
<j152>USD</j152>
<b251>ZA</b251>
</price>
<price>
<j148>02</j148>
<j151>12.33</j151>
<j152>USD</j152>
<b251>ZA</b251>
</price>
<price>
<j148>01</j148>
<j151>149.57</j151>
<j152>ZAR</j152>
<b251>ZA</b251>
</price>
<price>
<j148>02</j148>
<j151>172.00</j151>
<j152>ZAR</j152>
<b251>ZA</b251>
</price>
</supplydetail>
</product>
I am trying to only return the last value found. eg: <j151>172.00</j151> at the moment it is finding all four values.i need to just return the last value.
So before we start I had to make the provided xml file an valid xml file (insert
<?xml version="1.0"?>
and a
<data>
tag that surrounded your data.
Assuming the xml file is located in a files directory in the directory the python file resides this is the minimal code to run it:
import xml.etree.ElementTree as ET
tree = ET.parse('files/text.xml')
root = tree.getroot()
listing = root.findall("product/supplydetail/price/j151")
end = len(listing) - 1
print(listing[end].tag)
print(listing[end].text)
As I had not to do anything with the lower tags I could just jump to the path where the j151 reside.
The following function returns a list according to the doku
root.findall("...")
As you mentioned you always want to get the last of the prices which correspond to the last entry of list. We then have to get how many entries this list has and (as list in python are starting at index 0) have to subtract 1.
You should only use the code on trusted XML als the lib you are using is known vulnerable to attacks.
Hope that gave you some hints, Cheerio.
I have a problem with identifying if a point is within a polygon or not.
For the same latitude and longitude, sometimes I get right results, but sometimes not. I get wrong results if I search for more IDs (so there are more events) or I change the time range (not necessarily bigger).
The line which causes the issue: | lookup some_lookup_name latitude longitude
I have reproduced the issue with sample data and simple geospatial lookup. All events with id=1 are inside the geofence, events with id=2 are outside. I am getting incorrect results (different when sorting according to time). I have two sample data sources (data_sample_2 has changed latitude in one of the events for id=2, from 51.501835 to 51.501836).
When sorting from earliest to latest, all events are inside
When sorting from latest to earliest, some events for id=1 are outside (which is incorrect)
Removing event with problematic latitude
Search:
index="debug_idx" source="data_sample_1"
| eval time_epoch=_time
| sort 0 _time
| lookup geo_4 latitude longitude
| table id latitude longitude _time time_epoch featureId featureCollection
| noop search_optimization=false
Data_sample_1:
{"location":{"state":{"position":{"timestamp":"2021-01-11T01:14:34.000Z","latitude":51.501835,"longitude":6.906453}}},"ident":{"attr":{"id":"2"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-11T01:14:34.000Z","latitude":51.501835,"longitude":6.906453}}},"ident":{"attr":{"id":"2"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:23:23.000Z","latitude":53.500091,"longitude":9.909387}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:16:58.000Z","latitude":53.49732,"longitude":9.9082}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:13:30.000Z","latitude":53.501923,"longitude":9.910017}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:13:15.000Z","latitude":53.501923,"longitude":9.910017}}},"ident":{"attr":{"id":"1"}}}}
Data_sample_2:
{"location":{"state":{"position":{"timestamp":"2021-01-11T01:14:34.000Z","latitude":51.501836,"longitude":6.906453}}},"ident":{"attr":{"id":"2"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-11T01:14:34.000Z","latitude":51.501835,"longitude":6.906453}}},"ident":{"attr":{"id":"2"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:23:23.000Z","latitude":53.500091,"longitude":9.909387}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:16:58.000Z","latitude":53.49732,"longitude":9.9082}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:13:30.000Z","latitude":53.501923,"longitude":9.910017}}},"ident":{"attr":{"id":"1"}}}}
{"location":{"state":{"position":{"timestamp":"2021-01-06T22:13:15.000Z","latitude":53.501923,"longitude":9.910017}}},"ident":{"attr":{"id":"1"}}}}
Geolookup_4.kml:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="geo_4" id="geo_4">
<SimpleField name="Name" type="string"></SimpleField>
</Schema>
<Folder>
<name>geo_4</name>
<Placemark>
<name>{"place":"Location 1","category":"Locations","description":["A"],"subdescription":"01"}</name>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<Polygon><outerBoundaryIs><LinearRing><coordinates>9.92195,53.51249 9.92848,53.49588 9.89352,53.49482 9.89561,53.51567 9.92195,53.51249</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
</Folder>
</Document></kml>
Hi I am trying to use retrofit to write a simple rest client , I am trying to call a REST API GET that returns an xml response, however retrofit is not able to parse the xml.
Retrofit Code
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
// Create an instance of our OfferClient API interface.
OfferClient offerClient = retrofit.create(OfferClient.class);
// Create a call instance for looking up offers.
String offerID="20000798";
Call<Offer> call = offerClient.offers(offerID);
Offer offer = call.execute().body();
System.out.println("Offer Response..."+ offer.getDescription());
Exception in thread "main" java.lang.RuntimeException:
org.simpleframework.xml.core.ElementException: Element 'featureSetID'
does not have a match in class
com.intuit.schema.platform.webs.catalog.internal.offers.v3.Offer$Product
at line 1
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:44)
at
Response that could not be un-marshalled.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<offer xmlns="http://schema.intuit.com/platform/webs/catalog/internal/offers/v3">
<offerID>20000798</offerID>
<name>QBOA + QBO Plus + QBOP Enhanced CA CAD for Accountants</name>
<description>QBOA + QBO Plus + QBOP Enhanced CA CAD for Accountants</description>
<effectiveStartDate>2015-12-13T00:00:00-0800</effectiveStartDate>
<currency>CAD</currency>
<region>CA</region>
<country>CA</country>
<offerType>Free</offerType>
<offerLevel>BASE</offerLevel>
<customerSegment>ACCOUNTANT</customerSegment>
<extendedCustomerSegment>REGULAR</extendedCustomerSegment>
<salesChannel>DIRECT</salesChannel>
<isListPriceOffer>true</isListPriceOffer>
<product>
<productID>22000220</productID>
<packageId>21001070</packageId>
<code>QBOA</code>
<name>QuickBooks Online Accountant</name>
<description>QuickBooks Online Accountant</description>
<grantOfferingType>Intuit.smallbusiness.qba.web</grantOfferingType>
<billingServiceType>/service/intuit/qboa</billingServiceType>
<featureSet>
<featureSetID>25001595</featureSetID>
<code>QBOA_STANDARD</code>
<name>QBO Accountant Standard</name>
<status>Active</status>
<description>QuickBooks Online Accountant Standard</description>
<feature>
<code>STANDARD</code>
<name>Standard</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001499</chargeID>
<name>QuickBooks Online Accountant Standard</name>
<description>QuickBooks Online Accountant Standard CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
</product>
<product>
<productID>22000000</productID>
<packageId>21001071</packageId>
<code>QBO</code>
<name>QuickBooks Online</name>
<description>QuickBooks Online</description>
<grantOfferingType>Intuit.sbe.salsa.default</grantOfferingType>
<billingServiceType>/service/intuit/qbo</billingServiceType>
<featureSet>
<featureSetID>25000000</featureSetID>
<code>QBO_PLUS</code>
<name>QBO_PLUS</name>
<status>Active</status>
<description>QuickBooks Online Plus</description>
<feature>
<code>PLUS</code>
<name>Plus</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001500</chargeID>
<name>QuickBooks Online Plus</name>
<description>QuickBooks Online Plus Accountant CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
</product>
<product>
<productID>22000154</productID>
<dependentOnProductId>22000000</dependentOnProductId>
<dependentOnProductCode>QBO</dependentOnProductCode>
<packageId>21001323</packageId>
<code>QBOP</code>
<name>QuickBooks Online Payroll</name>
<description>QuickBooks Online Payroll</description>
<grantOfferingType>Intuit.ems.iop</grantOfferingType>
<billingServiceType>/service/intuit/qbo/qbop</billingServiceType>
<featureSet>
<featureSetID>25000537</featureSetID>
<code>ENHANCED</code>
<name>ENHANCED</name>
<status>Active</status>
<description>ENHANCED</description>
<feature>
<code>ENHANCED</code>
<name>Enhanced</name>
<type>Feature Set</type>
</feature>
</featureSet>
<charge>
<chargeID>23001868</chargeID>
<name>QuickBooks Online Payroll Enhanced</name>
<description>QuickBooks Online Payroll Enhanced CA CAD Monthly Free</description>
<type>Recurring</type>
</charge>
<charge>
<chargeID>23001964</chargeID>
<name>QuickBooks Online Payroll Enhanced Usage</name>
<description>QuickBooks Online Payroll Enhanced Accountant CA CAD Usage Free</description>
<type>Usage</type>
</charge>
</product>
<transition>
<transitionType>Resubscribe</transitionType>
<fromOfferID>20000798</fromOfferID>
<toOfferID>20000798</toOfferID>
</transition>
</offer>
Replace addConverterFactory(SimpleXmlConverterFactory.create()) with addConverterFactory(SimpleXmlConverterFactory.createNonStrict()) in your retrofit builder. This will make the parser tolerant to xml tags which do not occur in your POJO
When I query multiple fields for a string, is it possible to retrieve information in which field the query term was found ?
I want to query description, information, additional information ... But then I need to know which field gave the result As I want to give different layouts.
Lucene way: look at IndexSearcher.explain(...). This will give an Explanation that describes how doc scored against query.
Solr way: add &debugQuery=true. I queried for collection:61 and got this document:
<doc>
<str name="collection">61</str>
...other fields...
<long name="uuid">1111</long>
</doc>
And then below comes this
<lst name="explain">
<str name="1111">
0.882217 = (MATCH) fieldWeight(collection:61 in 0), product of: 1.0 =
tf(termFreq(collection:61)=1) 0.882217 = idf(docFreq=8, maxDocs=8) 1.0 =
fieldNorm(field=collection, doc=0)
</str>
...
</lst>
Above basically tells that item 1111 had field collection with value 61. You can also request for debug.explain.structured to get this explanation string in a more structured format.
I suppose the solution is simple, but I haven't found an answer despite searching the internet extensively. Please help! The problem is : my xml query is not returning the required result if the required attribute is not inside the first element of similarly named elements. For example, this code is not returning anything:
XElement xelement = XElement.Load("~/Employees.xml"));
var homePhone = from phoneno in xelement.Elements("Employee")
where (string)phoneno.Element("Phone").Attribute("Type") == "Work"
select phoneno;
foreach (XElement xEle in homePhone)
TextBox1.Text= xEle + "/n";
However, if I substitute "Work" with "Home", I get the required result. In fact, I should get exactly the same result with "Work". Can someone please explain how to do this?
The xml template is:
<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee>
<EmpId>1</EmpId>
<Name>Sam</Name>
<Sex>Male</Sex>
<Phone Type="Home">423-555-0124</Phone>
<Phone Type="Work">424-555-0545</Phone>
<Address>
<Street>7A Cox Street</Street>
<City>Acampo</City>
<State>CA</State>
<Zip>95220</Zip>
<Country>USA</Country>
</Address>
</Employee>
<Employee>
<EmpId>2</EmpId>
<Name>Lucy</Name>
<Sex>Female</Sex>
<Phone Type="Other">143-555-0763</Phone>
<Phone Type="Work">434-555-0567</Phone>
<Address>
<Street>Jess Bay</Street>
<City>Alta</City>
<State>CA</State>
<Zip>95701</Zip>
<Country>USA</Country>
</Address>
</Employee>
<Employee>
<EmpId>3</EmpId>
<Name>Kate</Name>
<Sex>Female</Sex>
<Phone Type="Home">166-555-0231</Phone>
<Phone Type="Other">233-555-0442</Phone>
<Address>
<Street>23 Boxen Street</Street>
<City>Milford</City>
<State>CA</State>
<Zip>96121</Zip>
<Country>USA</Country>
</Address>
</Employee>
<Employee>
<EmpId>4</EmpId>
<Name>Chris</Name>
<Sex>Male</Sex>
<Phone Type="Work">564-555-0122</Phone>
<Phone Type="Other">442-555-0154</Phone>
<Address>
<Street>124 Kutbay</Street>
<City>Montara</City>
<State>CA</State>
<Zip>94037</Zip>
<Country>USA</Country>
</Address>
</Employee>
</Employees>
XElement.Element("name") will return the FIRST element of the given name when there is more than one. You really want this:
var employeesWithHomePhone = from e in xdocument.Root.Elements("Employee")
where e.Elements("Phone").Any( p => (string)p.Attribute("Type") == "Home")
select e;
And just change "Home" to "Work" to get the ones with a Work number
This line:
where (string)phoneno.Element("Phone")
is indeed using only the first Phone element since you requested only one. You need to use the Elements method, but you can iterate all phones instead of employees:
from phone in xelement.Descendants("Phone")
where (string)phone.Attribute("Type") == "Work"
select phone;
If you want to make sure this phone belongs to an employee add this condition in the where:
phone.Parent.Name == "Employee"