I have a XML file in this format:
<league country="argentina" name="Argentina: Torneo Federal A - Winners Stage" cup="False" id="2909" sub_id="29094">
<match alternate_id="4187269" alternate_id_2="4394549" date="14.08.2015" id="4304775" static_id="14081523515562337775" status="FT" time="18:00">
<home goals="2" id="2351556" name="Club Atletico Mitre"></home>
<away goals="1" id="2337775" name="Chaco For Ever"></away>
<events>
<event assist="" assistid="" id="22958994" minute="32" player="Juan Pablo Villafane" playerid="" result="[1 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="22958995" minute="48" player="Aldo Visconti" playerid="" result="[1 - 1]" team="away" type="goal"></event>
<event assist="" assistid="" id="22958996" minute="90" player="Emanuel Lazzarini" playerid="" result="[2 - 1]" team="home" type="goal"></event>
</events>
<ht score="[1-0]"></ht>
<ft score="[2-1]"></ft>
</match></league><league country="argentina" name="Argentina: Torneo Federal A - Losers Stage" cup="False" id="2909" sub_id="29095"><match alternate_id="4178253" alternate_id_2="4410516" date="14.08.2015" id="4295774" static_id="14081523557572337894" status="FT" time="18:00">
<home goals="2" id="2355757" name="Velez de San Ramon"></home>
<away goals="1" id="2337894" name="Sportivo Patria"></away>
<events>
<event assist="" assistid="" id="23118664" minute="11" player="Diego Suarez" playerid="" result="[1 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="23118665" minute="64" player="Luis Leguizamon" playerid="" result="[2 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="23118666" minute="67" player="Rodrigo Ramirez (o.g.)" playerid="" result="[2 - 1]" team="away" type="goal"></event>
</events>
<ht score="[1-0]"></ht>
<ft score="[2-1]"></ft>
This is my controller:
xml = Nokogiri::XML(f)
path = "//match[#static_id='user.matchid']"
#country = xml.xpath(path)
How can I get the name of team, based on the condition that value of attribute "result" = [1-0] or [0-1]?
I'd do something like:
require 'nokogiri'
doc = Nokogiri::XML(<<EOT)
<xml>
<league>
<match>
<events>
<event player="Juan Pablo Villafane" result="[1 - 0]" team="home"></event>
<event player="Aldo Visconti" result="[1 - 1]" team="away"></event>
</events>
<events>
<event player="Diego Suarez" result="[1 - 0]" team="home"></event>
<event player="Luis Leguizamon" result="[2 - 0]" team="home"></event>
</events>
</match>
</league>
</xml>
EOT
doc.search('//event[contains(#result, "[1 - 0]") or contains(#result, "[0 - 1]")]/#team').map(&:text)
# => ["home", "home"]
It isn't stated clearly what is the condition to check exactly. So, here is an example condition for context, suppose you want to get name of home team of a match where final time score is "[2-1]" :
//match[ft/#score = '[2-1]']/home/#name
Related
Suppose we have this xml:
<question>
<test id="1">
<tag k="a" v="1"/>
<tag k="a" v="2"/>
<tag k="b" v="3"/>
</test>
<test id="2">
<tag k="a" v="1"/>
<tag k="a" v="4"/>
<tag k="b" v="5"/>
</test>
<test id="3">
<tag k="a" v="2"/>
<tag k="a" v="6"/>
<tag k="b" v="7"/>
</test>
</question>
I would like to return all values v of test, if k = "a" AND v = "1", like this:
v="3"
v="5"
So far my approach:
for $i in //test
where ($i/tag[#k = 'a' and #v = '1'])
return $i/tag/#v
But this is not correct because thats the return:
v="1"
v="2"
v="3"
v="1"
v="4"
v="5"
Thank you for your help :)
You are probably looking for something like
for $i in //test
where ($i/tag[#k = 'a'][#v="1"])
return $i/tag[#k="b"]/#v
Your criteria for selection was not exactly clear, but this returns what you expected:
for $i in //test
where $i/tag[#k = 'a' and #v = '1']
return $i/tag[not(#k = 'a' or #v = '1')]/#v
You could simplify and do this in a single XPath expression:
//test/tag[#k = 'a' and #v = '1']/tag[not(#k = 'a' or #v = '1')]/#v
I have an XML + SOAP with Nokogiri and I want only the body to appear but I have some errors.
The XML SOAP is:
data = <SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">
<SOAP:Header><header xmlns=\"xmlapi_1.0\">
<requestID>aquiroga:0001</requestID>
<requestTime>Mar 14, 2018 11:33:27 PM</requestTime>
<responseTime>Mar 14, 2018 11:33:27 PM</responseTime>
</header>
</SOAP:Header>
<SOAP:Body>
<findResponse xmlns=\"xmlapi_1.0\">
<result>
<service.SapEgrQosQueueStatsLogRecord>
<queueId>2</queueId>
<droppedInProfOctets>0</droppedInProfOctets>
<droppedOutProfOctets>0</droppedOutProfOctets>
<timeCaptured>1521072355115</timeCaptured>
<periodicTime>0</periodicTime>
<displayedName>eNodo_B-HOTELPUERTOPALMERA-S1UX2</displayedName>
<monitoredObjectSiteName>SMT-TRS-AN01</monitoredObjectSiteName>
</service.SapEgrQosQueueStatsLogRecord>
<service.SapEgrQosQueueStatsLogRecord>
<queueId>1</queueId>
<droppedInProfOctets>0</droppedInProfOctets>
<droppedOutProfOctets>70450698</droppedOutProfOctets>
<timeCaptured>1521072355051</timeCaptured>
<periodicTime>199796</periodicTime>
<displayedName>to_eNODOB Tarapoto Sur-S1-MME</displayedName>
<monitoredObjectSiteName>SMT-TRS-AN01</monitoredObjectSiteName>
</service.SapEgrQosQueueStatsLogRecord>
</result>
</findResponse>
</SOAP:Body>
</SOAP:Envelope>
The code I am using is:
data_stats = data.xpath('/SOAP:Envelope/SOAP:Body')
The result is:
=> #<Nokogiri::XML::Element:0x3fee745c1c94 name="Body" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1e60 prefix="SOAP" href="http://schemas.xmlsoap.org/soap/envelope/"> children=[#<Nokogiri::XML::Element:0x3fee745c16b8 name="findResponse" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c126c name="result" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c0e84 name="service.SapEgrQosQueueStatsLogRecord" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Element:0x3fee745c0a60 name="queueId" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745c0664 "1">]>, #<Nokogiri::XML::Element:0x3fee745c0498 name="droppedInProfOctets" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745c00b0 "0">]>, #<Nokogiri::XML::Element:0x3fee745adec4 name="droppedOutProfOctets" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745adaa0 "0">]>, #<Nokogiri::XML::Element:0x3fee745ad8d4 name="timeCaptured" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ad4c4 "1521158716279">]>, #<Nokogiri::XML::Element:0x3fee745ad2f8 name="periodicTime" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745aceac "284992">]>, #<Nokogiri::XML::Element:0x3fee745acce0 name="displayedName" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ac8bc "RTN VillaSalvador3 Tdp-VillaBaja">]>, #<Nokogiri::XML::Element:0x3fee745ac6dc name="monitoredObjectSiteName" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0"> children=[#<Nokogiri::XML::Text:0x3fee745ac2b8 "LIM-SPO-AN02">]>]>, #<Nokogiri::XML::Element:0x3fee74593f9c name="service.SapEgrQosQueueStatsLogRecord" namespace=#<Nokogiri::XML::Namespace:0x3fee745c1668 href="xmlapi_1.0">
I want it to appear only from service.SapEgrQosQueueStatsLogRecord. The code I use is the following:
data_stats = qos7705egressdiscard_summary.xpath('/SOAP:Envelope/SOAP:Body/findResponse/result/service.SapEgrQosQueueStatsLogRecord')
But the result is an empty arrangement => []
You can use data.remove_namespaces! ( see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Document:remove_namespaces! ). Then this query works:
data.xpath('/Envelope/Body/findResponse/result/service.SapEgrQosQueueStatsLogRecord')
I am trying to create an XLS sheet programmatically. I am able to create single sheet in the XLS file, but when I try to create two sheets, I get the error. The file is created but I am unable to open the file. I can only open the file when it is created with single sheet.
Here is what I tried:
RSworkBook * folder = [ [RSworkBook alloc] init];
folder.author = #"andrea cappellotto";
folder.version = 1.2;
RSworkSheet * sheet = [[RSworkSheet alloc] initWithName:#"prova"];
RSworkSheet * sheet2 = [[RSworkSheet alloc] initWithName:#"222"];
RSworkSheetRow * row = [[RSworkSheetRow alloc] initWithHeight:20];
[row addCellString:#"prova"];
[row addCellString:#"prova2"];
[sheet addWorkSheetRow:row];
[sheet2 addWorkSheetRow:row];
RSworkSheetRow * row2 = [[RSworkSheetRow alloc] initWithHeight:25];
[row2 addCellNumber:100];
[row2 addCellData:[NSDate date] ];
[sheet addWorkSheetRow:row2];
[sheet2 addWorkSheetRow:row];
[folder addWorkSheet:sheet];
[folder addWorkSheet:sheet2];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
[folder writeWithName:#"prova" toPath:documentsDir];
HEre is the xml code that is generated:
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>andrea cappellotto</Author>
<LastAuthor>andrea cappellotto</LastAuthor>
<Created>2015-07-09</Created>
<Version>1.20</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>20000</WindowHeight>
<WindowWidth>20000</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>0</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook><Styles><Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center" ss:Horizontal="Center"/>
<Borders/>
<Font ss:FontName=".HelveticaNeueInterface-Regular" ss:Size="14.00" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s60">
<NumberFormat ss:Format="Short Date"/>
</Style>
</Styles>
<Worksheet ss:Name="prova">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="0.00" ss:DefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="25.00" >
<Cell>
<Data ss:Type="Number">100.00</Data>
</Cell>
<Cell ss:StyleID="s60">
<Data ss:Type="DateTime">2015-07-09</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
<Worksheet ss:Name="222">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="0.00" ss:DefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
</Workbook>
I found another library to create multiple sheets in a xls file. It is libxl.I can add as many sheets as I can by using the following line:
SheetHandle sheet = xlBookAddSheet(book, [sheetNAme UTF8String], NULL);
I'm trying to create a test invoice at quickbooks using quickbooks-ruby gem. Note I have a test account at QB which doesn't have anything: invoice, customer, etc. It's a new account created only for testing purpose. So here is my code:
service = Quickbooks::Service::Invoice.new
service.company_id = current_user.company_id
service.access_token = create_consumer
qb_invoice = Quickbooks::Model::Invoice.new
qb_invoice.customer_id = 123
line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = 100
line_item.sales_item! do |detail|
detail.unit_price = 100
detail.quantity = 1
detail.item_id = 1
end
qb_invoice.line_items << line_item
res = service.create qb_invoice
p res.id #exception!
def create_consumer
OAuth::AccessToken.new(.....)
end
Request:
METHOD = post
RESOURCE = https://qb.sbfinance.intuit.com/v3/company/fdsfdsfdsfds123/invoice
<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns="http://schema.intuit.com/finance/v3" sparse="false">
<Line>
<Amount>100.0</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef>1</ItemRef>
<UnitPrice>100.0</UnitPrice>
<RatePercent>0.0</RatePercent>
<Qty>1.0</Qty>
</SalesItemLineDetail>
</Line>
<CustomerRef>123</CustomerRef>
<TotalAmt>0.0</TotalAmt>
<Balance>0.0</Balance>
<Deposit>0.0</Deposit>
</Invoice>
and response with the error:
RESPONSE CODE = 400
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-06T19:30:49.168-08:00">
<Fault type="ValidationFault">
<Error code="2500" element="">
<Message>Invalid Reference Id</Message>
<Detail>Invalid Reference Id : Something you're trying to use has been deleted. Check the fields with accounts, customers, items, vendors or employees.
</Detail>
</Error>
</Fault>
</IntuitResponse>
Could it be because a customer with id = 123 doesn't exist? If not, what's the cause then?
Please check if you have a customer(ID-123) and Item(Id-1) exist in your account.
If not then create these two entries using apiexplorer/code and use the corresponding object IDs.
ApiExplorer - https://developer.intuit.com/apiexplorer?apiname=V3QBO
EntityRef - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference
ApiExplorer -
Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0015_firstrequest
Thanks
I run an affiliate website, and I have code that consumes the XML datafeeds. I have written a method that can scrape and store the data from the XML feed, it works perfectly for say 60 feeds we have. Each row in the feed is created as a #product.
Now enter Linkshare, the code I have that works for the other 60 feeds doesn't work for Linkshare feeds. Instead of having #products.count = a few hundred, it tries to load ALL products into ONE instance of #products, so I get:
Soul Cal Deluxe Heart Camisole Top - WomensOnly Vest Top - WomensSoul
Cal Deluxe Racer Back Vest Top - WomensSoul Cal Deluxe Racer Back Vest
Top - WomensSoul Cal Deluxe Racer Back Vest Top - WomensSoul Cal
Deluxe Racer Back Vest Top - WomensCrafted Grunge Jumper - WomensMiso
Pearl & Fireball Ring Stack - WomensSoul Cal Deluxe Checked Shacket -
MensSoul Cal Deluxe Hines Stripe Shirt - MensMiso Embellished Waist
Dress - WomensGlamorous Belted Dress - WomensMiso Front Tie Shorts -
WomensMiso Tie Front Shorts - WomensSoul Cal Deluxe Stretch Skinny
Trousers - WomensSoul Cal Deluxe Stretch Skinny Trousers - WomensSoul
Cal Deluxe Stretch Skinny Trousers - WomensVero Moda Bernice Dress -
WomensMiso Dipped Hem Maxi Dress - WomensSoul Cal Deluxe Belted Chinos
- WomensSoul Cal Deluxe Stretch Skinny Trousers - WomensMiso Jewel Bodycon Dress - WomensMiso Evening Bandeau Dress - WomensMiso Aztec
Tube Skirt - WomensCrafted Embellished Neck Dress - WomensMiso Spot
Dress - WomensMiso Spot Dress - Womens"}]
(Note, I took just the end of the console log, but you see what I mean.
I've run lots of testing, this has been a problem we've had for a while.
Has anyone had anything like this?
Could it be doctypes or hpricot?
Any Suggestions?
Example feed:
<?xml version="1.0" encoding="UTF-8"?><merchandiser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="merchandiser.xsd">
<header><merchantId>36503</merchantId><merchantName>Republic</merchantName><createdOn>2012-01-12/20:21:17</createdOn></header><product product_id="73794" name="Soul Cal Deluxe Borg DLX Zip Through Hoody - Mens" sku_number="73794" manufacturer_name="Soul Cal Deluxe" part_number="73794"><category><primary>Men > Sweats & Hoodies</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.73794&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F73794</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/73794/73794_lg1.jpg</productImage><buy></buy></URL><description><short>Blue, Hoodies, Hand wash only</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">34.99</sale><retail>34.99</retail></price><brand>Soul Cal Deluxe</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.73794&type=15&subid=0</pixel></product>
<product product_id="51118" name="Jack & Jones Dale Jack Jeans - Mens" sku_number="51118" manufacturer_name="Jack&Jones" part_number="51118"><category><primary>Men > Jeans</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.51118&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F51118</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/51118/51118_lg1.jpg</productImage><buy></buy></URL><description><short>Blue, Straight</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">40.00</sale><retail>64.99</retail></price><brand>Jack&Jones</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.51118&type=15&subid=0</pixel></product>
<product product_id="51128" name="Diesel Straight Leg Larkee Jeans - Mens" sku_number="51128" manufacturer_name="Diesel" part_number="51128"><category><primary>Men > Jeans</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.51128&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F51128</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/51128/51128_lg1.jpg</productImage><buy></buy></URL><description><short>Blue, Straight</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">120.00</sale><retail>120.00</retail></price><brand>Diesel</brand><shipping><cost currency="GBP"><amount>0.00</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.51128&type=15&subid=0</pixel></product>
<product product_id="68226" name="Miso Fox Scarf - Womens" sku_number="68226" manufacturer_name="Miso" part_number="68226"><category><primary>Women > Accessories</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.68226&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F68226</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/68226/68226_lg1.jpg</productImage><buy></buy></URL><description><short>Stone, Scarves, Machine washable</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">5.00</sale><retail>19.99</retail></price><brand>Miso</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.68226&type=15&subid=0</pixel></product>
<product product_id="67968" name="Levis Pleat Trucker Jacket - Womens" sku_number="67968" manufacturer_name="Levis" part_number="67968"><category><primary>Women > Coats & Jackets</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.67968&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F67968</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/67968/67968_lg1.jpg</productImage><buy></buy></URL><description><short>Blue, Jackets</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">30.00</sale><retail>84.99</retail></price><brand>Levis</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.67968&type=15&subid=0</pixel></product>
<product product_id="81217" name="G-Star Dean Army Tapered Jeans - Womens" sku_number="81217" manufacturer_name="G-Star" part_number="81217"><category><primary>Women > Jeans</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.81217&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F81217</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/81217/81217_lg1.jpg</productImage><buy></buy></URL><description><short>Black, Straight</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">115.00</sale><retail>115.00</retail></price><brand>G-Star</brand><shipping><cost currency="GBP"><amount>0.00</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.81217&type=15&subid=0</pixel></product>
<product product_id="58377" name="Police 883 Embro Hat - Mens" sku_number="58377" manufacturer_name="Police 883" part_number="58377"><category><primary>Men > Accessories</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.58377&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F58377</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/58377/58377_lg1.jpg</productImage><buy></buy></URL><description><short>Black, Hats & Beanies</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">17.99</sale><retail>17.99</retail></price><brand>Police 883</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.58377&type=15&subid=0</pixel></product>
<product product_id="58306" name="Diesel Kyle Beanie - Mens" sku_number="58306" manufacturer_name="Diesel" part_number="58306"><category><primary>Men > Accessories</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.58306&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F58306</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/58306/58306_lg1.jpg</productImage><buy></buy></URL><description><short>Black, Hats & Beanies</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">19.99</sale><retail>19.99</retail></price><brand>Diesel</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.58306&type=15&subid=0</pixel></product>
<product product_id="86865" name="Miso Fair Isle Cardigan - Womens" sku_number="86865" manufacturer_name="Miso" part_number="86865"><category><primary>Women > Knitwear</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.86865&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F86865</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/86865/86865_lg1.jpg</productImage><buy></buy></URL><description><short>Stone, Cardigans, Hand wash only</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">49.99</sale><retail>49.99</retail></price><brand>Miso</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.86865&type=15&subid=0</pixel></product>
<product product_id="52947" name="White Label Chinos - Mens" sku_number="52947" manufacturer_name="White Label" part_number="52947"><category><primary>Men > trs</primary><secondary></secondary></category><URL><product>http://click.linksynergy.com/link?id=g*0hRDNOv4M&offerid=215450.52947&type=15&murl=http%3A%2F%2Fwww.republic.co.uk%2Finvt%2F52947</product><productImage>http://www.republic.co.uk/content/ebiz/republic/invt/52947/52947_lg1.jpg</productImage><buy></buy></URL><description><short>Stone, Chinos, Machine washable</short><long></long></description><discount currency="GBP"><amount></amount><type>amount</type></discount><price currency="GBP"><sale begin_date="" end_date="">20.00</sale><retail>20.00</retail></price><brand>White Label</brand><shipping><cost currency="GBP"><amount>3.95</amount><currency>GBP</currency></cost><information></information><availability></availability></shipping><keywords></keywords><upc></upc><m1></m1><pixel>http://ad.linksynergy.com/fs-bin/show?id=g*0hRDNOv4M&bids=215450.52947&type=15&subid=0</pixel></product>
One problem is that the XML is malformed. The <merchandiser> tag is not terminated. Nokogiri will tell you as much if you check the errors method after parsing the document:
doc.errors
[
[0] #<Nokogiri::XML::SyntaxError:0x10109b918
attr_reader :code = 77,
attr_reader :column = 1,
attr_reader :domain = 1,
attr_reader :file = nil,
attr_reader :int1 = 1,
attr_reader :level = 3,
attr_reader :line = 12,
attr_reader :str1 = "merchandiser",
attr_reader :str2 = nil,
attr_reader :str3 = nil
>
]
Adding a closing </merchandiser> tag at the end of the file cleared that up:
doc = Nokogiri::XML(File.read('./test.xml'))
#<Nokogiri::XML::Document:0x1009ae038
#node_cache = [],
attr_accessor :errors = [],
attr_reader :decorators = nil
>
After fixing that I parsed for product:
doc.search('product').size
=> 20
There are <product> collisions:
<product>
<URL>
<product />
</URL>
</product>
which could confuse your code. It confused my search above that reported 20 occurrences.