walmart upload an item feed sample xml - php

I need any sample working XML for upload an item using walmart api.
I have tried a lot to create an XML but no success.
Below is my testing XML Data.
<?xml version="1.0" encoding="UTF-8" ?>
<MPItemFeed xmlns="http://walmart.com/">
<MPItemFeedHeader>
<version>3.1</version>
</MPItemFeedHeader>
<MPItem>
<sku>78350426190609</sku>
<processMode>CREATE</processMode>
<productIdentifiers>
<productIdentifier>
<productIdType>UPC</productIdType>
<productId>78350426113604</productId>
</productIdentifier>
</productIdentifiers>
<MPProduct>
<productName>Electronic Cables_ Update3</productName>
<ProductIdUpdate>Yes</ProductIdUpdate>
<SkuUpdate>No</SkuUpdate>
<category>
<Electronics>
<ElectronicsCables>
<shortDescription>new United Facility Supply High-Volume Wrapping paper this is change to Partial update on PROMode is REPLACE_ALL</shortDescription>
<manufacturer>ECManu</manufacturer>
<manufacturerPartNumber>ECManu0354</manufacturerPartNumber>
<modelNumber>ECMan49_update</modelNumber>
<brand>NewECB brand</brand>
<mainImageUrl>https://i5.walmartimages.com/asr/d225a57c-18fa-46f1-b160-7e61a6fae8b1_1.487e4418d1c56266742b8a6942a3ac5e.jpeg</mainImageUrl>
<productSecondaryImageURL>
<productSecondaryImageURLValue>https://i5.walmartimages.com/asr/414422b1-b13a-40b5-9bdc-adfe24a0bad8_1.3473a55982153dc1dfb17294123124f5.jpeg</productSecondaryImageURLValue>
</productSecondaryImageURL>
<color>Blue</color>
<cableLength>
<measure>18.00</measure>
<unit>in</unit>
</cableLength>
<batteryTechnologyType>Alkaline</batteryTechnologyType>
<isProp65WarningRequired>No</isProp65WarningRequired>
</ElectronicsCables>
</Electronics>
</category>
</MPProduct>
</MPItem>
</MPItemFeed>
I am getting this response.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:PartnerFeedResponse xmlns:ns2="http://walmart.com/">
<ns2:feedId>A9CCFBD2054B43859744FE50DFADB9B3#AQMBAAA</ns2:feedId>
<ns2:feedStatus>PROCESSED</ns2:feedStatus>
<ns2:ingestionErrors/>
<ns2:itemsReceived>1</ns2:itemsReceived>
<ns2:itemsSucceeded>0</ns2:itemsSucceeded>
<ns2:itemsFailed>1</ns2:itemsFailed>
<ns2:itemsProcessing>0</ns2:itemsProcessing>
<ns2:offset>0</ns2:offset>
<ns2:limit>50</ns2:limit>
<ns2:itemDetails/>
</ns2:PartnerFeedResponse>
How can I fix the above XML data?

Swap the positions of the processMode and sku tags like so:
<MPItem>
<processMode>CREATE</processMode>
<sku>78350426190609</sku>
<productIdentifiers>
You can find the current XSDs at
https://developer.walmart.com/xsd/V3-Spec-Item-3.1-XSD.zip
-
You may want to look into an XML validator to help find errors like this.

The below XML is a sample XML for v3 item feed for Walmart Product Upload
<?xml version="1.0"?>
<MPItemFeed xmlns="http://walmart.com/">
<MPItemFeedHeader>
<version>3.1</version>
<mart>WALMART_CA</mart>
<locale>en_CA</locale>
</MPItemFeedHeader>
<MPItem>
<sku>437764</sku>
<productIdentifiers>
<productIdentifier>
<productIdType>UPC</productIdType>
<productId>028617433790</productId>
</productIdentifier>
</productIdentifiers>
<MPProduct>
<productName>Bistro Chalk Marker Chisel Tip-Silver 483-C-SLV</productName>
<ProductIdUpdate>No</ProductIdUpdate>
<SkuUpdate>No</SkuUpdate>
<category>
<ArtAndCraftCategory>
<ArtAndCraft>
<shortDescription>Bistro Chalk Marker Chisel Tip-Silver 483-C-SLV</shortDescription>
<brand>Uchida</brand>
<mainImageUrl>https://www.stuff4crafts.com/media/catalog/product/4/3/437764.jpg</mainImageUrl>
</ArtAndCraft>
</ArtAndCraftCategory>
</category>
</MPProduct>
<MPOffer>
<price>3.99</price>
<MinimumAdvertisedPrice>3.99</MinimumAdvertisedPrice>
<ShippingWeight>
<measure>0.8000</measure>
<unit>lb</unit>
</ShippingWeight>
<ProductTaxCode>2038710</ProductTaxCode>
</MPOffer>
</MPItem>
</MPItemFeed>
processMode is default CREATE . You can either use it or skip it. If used it should be above tag.

Related

Parse last item XML PHP using xpath (Russian Post tracking API)

I have some difficult parsing the last element (ns3:Name and
ns3:OperDate) from Russian post tracking API using PHP.
Tried a few xpath queries without success.
Any help will be appreciated.
Here is example of the XML:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
<S:Body>
<ns7:getOperationHistoryResponse xmlns:ns7="http://russianpost.org/operationhistory" xmlns:ns2="http://russianpost.org/sms-info/data" xmlns:ns3="http://russianpost.org/operationhistory/data" xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns5="http://www.russianpost.org/custom-duty-info/data" xmlns:ns6="http://www.russianpost.org/RTM/DataExchangeESPP/Data">
<ns3:OperationHistoryData>
<ns3:historyRecord>
<ns3:AddressParameters>
<ns3:OperationAddress>
<ns3:Index>102976</ns3:Index>
<ns3:Description>MR LC Vnukovo Cex-1</ns3:Description>
</ns3:OperationAddress>
<ns3:CountryFrom>
<ns3:Id>643</ns3:Id>
<ns3:Code2A>RU</ns3:Code2A>
<ns3:Code3A>RUS</ns3:Code3A>
<ns3:NameRU>?????????? ?????????</ns3:NameRU>
<ns3:NameEN>Russian Federation</ns3:NameEN>
</ns3:CountryFrom>
<ns3:CountryOper>
<ns3:Id>643</ns3:Id>
<ns3:Code2A>RU</ns3:Code2A>
<ns3:Code3A>RUS</ns3:Code3A>
<ns3:NameRU>?????????? ?????????</ns3:NameRU>
<ns3:NameEN>Russian Federation</ns3:NameEN>
</ns3:CountryOper>
</ns3:AddressParameters>
<ns3:FinanceParameters>
<ns3:Payment>0</ns3:Payment>
<ns3:Value>0</ns3:Value>
<ns3:MassRate>0</ns3:MassRate>
<ns3:InsrRate>0</ns3:InsrRate>
<ns3:AirRate>0</ns3:AirRate>
<ns3:Rate>0</ns3:Rate>
<ns3:CustomDuty>0</ns3:CustomDuty>
</ns3:FinanceParameters>
<ns3:ItemParameters>
<ns3:Barcode>RB842972220RU</ns3:Barcode>
<ns3:ValidRuType>false</ns3:ValidRuType>
<ns3:ValidEnType>false</ns3:ValidEnType>
<ns3:ComplexItemName>Small packet registered</ns3:ComplexItemName>
<ns3:MailType>
<ns3:Id>5</ns3:Id>
<ns3:Name>Small packet</ns3:Name>
</ns3:MailType>
<ns3:MailCtg>
<ns3:Id>1</ns3:Id>
<ns3:Name>Registered</ns3:Name>
</ns3:MailCtg>
<ns3:Mass>0</ns3:Mass>
</ns3:ItemParameters>
<ns3:OperationParameters>
<ns3:OperType>
<ns3:Id>8</ns3:Id>
<ns3:Name>Processing</ns3:Name>
</ns3:OperType>
<ns3:OperAttr>
<ns3:Id>0</ns3:Id>
<ns3:Name>Sorting</ns3:Name>
</ns3:OperAttr>
<ns3:OperDate>2016-12-20T22:56:13.000+03:00</ns3:OperDate>
</ns3:OperationParameters>
<ns3:UserParameters>
<ns3:SendCtg>
<ns3:Id>0</ns3:Id>
</ns3:SendCtg>
<ns3:Sndr>KAREPANOV</ns3:Sndr>
<ns3:Rcpn>PRONOVOST</ns3:Rcpn>
</ns3:UserParameters>
</ns3:historyRecord>
<ns3:historyRecord>
<ns3:AddressParameters>
<ns3:OperationAddress>
<ns3:Index>102972</ns3:Index>
<ns3:Description>MR LC Vnukovo MMPO Cex-2</ns3:Description>
</ns3:OperationAddress>
<ns3:MailDirect>
<ns3:Id>840</ns3:Id>
<ns3:Code2A>US</ns3:Code2A>
<ns3:Code3A>USA</ns3:Code3A>
<ns3:NameRU>??????????? ????? ???????</ns3:NameRU>
<ns3:NameEN>United States</ns3:NameEN>
</ns3:MailDirect>
<ns3:CountryFrom>
<ns3:Id>643</ns3:Id>
<ns3:Code2A>RU</ns3:Code2A>
<ns3:Code3A>RUS</ns3:Code3A>
<ns3:NameRU>?????????? ?????????</ns3:NameRU>
<ns3:NameEN>Russian Federation</ns3:NameEN>
</ns3:CountryFrom>
<ns3:CountryOper>
<ns3:Id>643</ns3:Id>
<ns3:Code2A>RU</ns3:Code2A>
<ns3:Code3A>RUS</ns3:Code3A>
<ns3:NameRU>?????????? ?????????</ns3:NameRU>
<ns3:NameEN>Russian Federation</ns3:NameEN>
</ns3:CountryOper>
</ns3:AddressParameters>
<ns3:FinanceParameters>
<ns3:Payment>0</ns3:Payment>
<ns3:Value>0</ns3:Value>
<ns3:MassRate>0</ns3:MassRate>
<ns3:InsrRate>0</ns3:InsrRate>
<ns3:AirRate>0</ns3:AirRate>
<ns3:Rate>0</ns3:Rate>
<ns3:CustomDuty>0</ns3:CustomDuty>
</ns3:FinanceParameters>
<ns3:ItemParameters>
<ns3:Barcode>RB842972220RU</ns3:Barcode>
<ns3:Internum>RB842972220RU</ns3:Internum>
<ns3:ValidRuType>false</ns3:ValidRuType>
<ns3:ValidEnType>false</ns3:ValidEnType>
<ns3:ComplexItemName>Small packet registered</ns3:ComplexItemName>
<ns3:MailRank>
<ns3:Id>0</ns3:Id>
<ns3:Name>Without rank</ns3:Name>
</ns3:MailRank>
<ns3:PostMark>
<ns3:Id>0</ns3:Id>
<ns3:Name>Without mark</ns3:Name>
</ns3:PostMark>
<ns3:MailType>
<ns3:Id>5</ns3:Id>
<ns3:Name>Small packet</ns3:Name>
</ns3:MailType>
<ns3:MailCtg>
<ns3:Id>1</ns3:Id>
<ns3:Name>Registered</ns3:Name>
</ns3:MailCtg>
<ns3:Mass>1700</ns3:Mass>
</ns3:ItemParameters>
<ns3:OperationParameters>
<ns3:OperType>
<ns3:Id>10</ns3:Id>
<ns3:Name>Export of international mail</ns3:Name>
</ns3:OperType>
<ns3:OperAttr>
<ns3:Id>0</ns3:Id>
</ns3:OperAttr>
<ns3:OperDate>2017-01-03T20:48:24.000+03:00</ns3:OperDate>
</ns3:OperationParameters>
<ns3:UserParameters>
<ns3:SendCtg>
<ns3:Id>0</ns3:Id>
</ns3:SendCtg>
<ns3:Sndr>KAREPANOV</ns3:Sndr>
<ns3:Rcpn>PRONOVOST</ns3:Rcpn>
</ns3:UserParameters>
</ns3:historyRecord>
</ns3:OperationHistoryData>
</ns7:getOperationHistoryResponse>
</S:Body>
</S:Envelope>
You can use the last()-test on node sets:
para[last()] selects the last para child of the context node
Concerning your question this would look as follows.
(//ns3:Name)[last()] | (//ns3:OperDate)[last()]
when applied to your sample xml, this expression yields the following result:
<ns3:Name>Export of international mail</ns3:Name>
<ns3:OperDate>2017:01:03T20:48:24.000+03:00</ns3:OperDate>

Getting info from a specific XML Node

I am trying to read the value for 3 specific XML nodes (bill_codes, sent_total, clicked_unique_total) I have done a lot of testing and I feel like I need someone with fresh eyes to look at this and help me find out what I no longer see..
I am using the simplexml_load_string function to load the XML into an array..
Here is the code that I have so far:
$xml = simplexml_load_string($content);
echo $xml->methodResponse->item->responseData->message_data->message->bill_codes;
This is the XML that I am using (comes from an API Call so I have no access to modifying/updating the structure of the XML)
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
<item>
<methodName>
<![CDATA[legacy.message_stats]]>
</methodName>
<responseData>
<message_data>
<message id="2345456">
<message_subject>
<![CDATA[#1 Item You Should Be Hoarding in 2015]]>
</message_subject>
<date_sent>2014-12-18 04:01:34</date_sent>
<message_notes>
<![CDATA[Sample Notes]]>
</message_notes>
<withheld_total>0</withheld_total>
<globally_suppressed>0</globally_suppressed>
<suppressed_total>0</suppressed_total>
<bill_codes>
<![CDATA[8578]]>
</bill_codes>
<sent_total>734273</sent_total>
<link_append_statement/>
<timezone/>
<message_name>
<![CDATA[Sample Message Name]]>
</message_name>
<optout_total>4054</optout_total>
<optout_rate_total>0.55</optout_rate_total>
<clicked_total>5363</clicked_total>
<clicked_unique>4350</clicked_unique>
<clicked_rate_unique>13.71</clicked_rate_unique>
<campaign_id>228640</campaign_id>
<campaign_type>C</campaign_type>
<included_groups>
<segment id="1208891">
<![CDATA[Segment Name Here]]>
</segment>
</included_groups>
<included_smartlists></included_smartlists>
<excluded_groups></excluded_groups>
<excluded_smartlists></excluded_smartlists>
<attributes></attributes>
<link id="40278272">
<has_name>1</has_name>
<clicked_unique_total>4350</clicked_unique_total>
</link>
</message>
</message_data>
</responseData>
<responseNum>
<![CDATA[1]]>
</responseNum>
<responseCode>
<![CDATA[201]]>
</responseCode>
</item>
</methodResponse>
No need to include the parent, just start with the ->item:
echo $xml->item->responseData->message_data->message->bill_codes;
Sample Output

Trouble figuring out how parsed xml is stored - simpleXML

Let's say my XML is like this:
<?xml version="1.0"?>
<lists>
<list
path=".">
<entry
kind="dir">
<name>Assignment1.1</name>
<commit
revision="1668">
<author>netid</author>
<date>2011-09-07T03:03:58.367692Z</date>
</commit>
</entry>
<entry
kind="file">
<name>Assignment1.1/.classpath</name>
<size>397</size>
<commit
revision="1558">
<author>netid</author>
<date>2011-09-06T17:00:52.998920Z</date>
</commit>
.
.
.
</list>
</lists>
And I store it in a SimpleXML object using
$xml_list = simplexml_load_file(dirname(__FILE__).'/svn_list.xml');
How would I access for example, the revision variable containing 1558?
I can't seem to figure it out using a combination of echo and print_r.
SimpleXML uses a set of classes which implement iterators to work through them, so you can loop through each node using foreach, however the easiest way to navigate the XML once it's loaded is by using SimpleXMLElement::xPath(). To get revision 1558, you can make the following call:
$commit = $xml_list->xpath('//list/entry/commit[#revision="1558"]');
This will return you the nodes underneath <commit revision="1558">, and you can then access them from the $commit variable, which extends ArrayObject.
To get the actual content of the <author> element, you must do the following:
print((string)$commit[0]->author);
SimpleXMLElement instances need to be cast to a type to expose their actual values.
Also, if you want to dump the content of $commit to see its child nodes, the easiest way is to call the asXml() method as follows:
print($commit[0]->asXml());
You are facing difficulties because you have error on your XML file , The </entry> tag was not closed.
You could traverse like this.
<?php
$xml='<lists>
<list>
<entry
kind="dir">
<name>Assignment1.1</name>
<commit
revision="1668">
<author>netid</author>
<date>2011-09-07T03:03:58.367692Z</date>
</commit>
</entry>
<entry
kind="file">
<name>Assignment1.1/.classpath</name>
<size>397</size>
<commit
revision="1558">
<author>netid</author>
<date>2011-09-06T17:00:52.998920Z</date>
</commit>
</entry>
</list>
</lists>';
$xml = simplexml_load_string($xml);
foreach ($xml->list->entry[0]->commit->attributes() as $a=>$v)
{
echo $v;
}
OUTPUT :
1668

PHP SimpleXMLElement not parsing <title> node

I have a simple well-formed XML doc that I'm writing to the page using PHP. For some reason the output never includes the title node, and after researching I can't figure this out. If I change the title node to 'heading' or some other name it is included in the output, but when its named 'title', this node is skipped.
Here's the XML doc code...
<?xml version="1.0" encoding="UTF-8"?>
<items>
<product>
<id>cd1</id>
<title>CD One</title>
<description>This is my first CD</description>
<img>/images/sample.jpg</img>
<price>14.99</price>
</product>
</items>
The PHP code looks like this...
<?php
$filename = '../catalog.xml';
$contents = file_get_contents($filename);
echo $contents;
?>
Well, the XML you posted is not valid XML;
The encoding should be in lowercase. Try with this string:
<?xml version="1.0" encoding="utf-8"?>
<items>
<product>
<id>cd1</id>
<title>CD One</title>
<description>This is my first CD</description>
<img>/images/sample.jpg</img>
<price>14.99</price>
</product>
</items>
Validate here: http://validator.w3.org/check

How to parse a specific xml file using PHP simpleXML

I know there is already a lot of topics about simpleXML and PHP, but I need help with an specific xml code.
<vitrine>
<canal>Hotwords</canal>
<product id="0">
<descricao>MP3 Apple iPod Class...</descricao>
<loja>ApetreXo.com</loja>
<preco>à vista R$765,22</preco>
<urlImagem>http://imagem.domain.com.br/thumbs/ensopado/18/80x80_107156_1.jpg</urlImagem>
<urlProduto>http://domain.com.br/tr/rd?o=BiY4C2UnHQ0LOWgyGjc3NRFp-</urlProduto>
</product>
<product id="1">
<descricao>TV Sony Bravia 3D LE...</descricao>
<loja>Fast Shop.com.b...</loja>
<preco>10 x R$299,90</preco>
<urlImagem>http://imagem.domain.com.br/thumbs/ensopado/2852/80x80_319373_1.jpg</urlImagem>
<urlProduto>http://domain.com.br/tr/rd?o=JDEn-</urlProduto>
</product>
</vitrine>
I need a foreach to get the data from each "product" like this:
<?
$feedUrl = 'url to xml file';
$rawFeed = file_get_contents($feedUrl);
$xml = simplexml_load_string($rawFeed);
foreach ($item ...????? ?)
{
}
How can I do this foreach to get the data. I tried all that I know without success.
Thanks.
First, you need <?xml version="1.0" encoding="UTF-8"?> as the first line in your XML, otherwise it's not valid. Then, and this will help you debug all sorts of things over your coding career, try this line:
echo "<pre>".print_r($xml,true)."</pre>";
That will give you the exact layout of the object you get back from the simplexml_load_string() call. From there, since you have a visual of the object layout, you should be able to figure out how to parse it. Incidentally, in your case, I think you'd need to do something like:
foreach($xml->vitrine as $element) {
// your code goes here
}
It seems PHP gets rid of evrything after the whitespace, because product id was changed to just product. Anyway here's the code.
<?php
$v = <<<ABC
<vitrine>
<canal>Hotwords</canal>
<product id="0">
<descricao>MP3 Apple iPod Class...</descricao>
<loja>ApetreXo.com</loja>
<preco>à vista R$765,22</preco>
<urlImagem>http://imagem.domain.com.br/thumbs/ensopado/18/80x80_107156_1.jpg</urlImagem>
<urlProduto>http://domain.com.br/tr/rd?o=BiY4C2UnHQ0LOWgyGjc3NRFp-</urlProduto>
</product>
<product id="1">
<descricao>TV Sony Bravia 3D LE...</descricao>
<loja>Fast Shop.com.b...</loja>
<preco>10 x R$299,90</preco>
<urlImagem>http://imagem.domain.com.br/thumbs/ensopado/2852/80x80_319373_1.jpg</urlImagem>
<urlProduto>http://domain.com.br/tr/rd?o=JDEn-</urlProduto>
</product>
</vitrine>
ABC;
$xml = simplexml_load_string($v);
//print_r($xml);
foreach ($xml->product as $c){
echo $c->loja; //echoing out value of 'loja'
}
Outputs
ApetreXo.com
Fast Shop.com.b...

Categories