Ebay motors api - Category is not valid. ID 33562 - ebay-api

Trying to post the item in ebay motors using ebay api call - AddItem. It throws me an error saying as below. Could you please show some light on this.
Note - I am able to add the item manually in ebay motors with compatability. I fetched the item details (which is added manually) using the api call - GetItem. Placed the same details in the AddItem api call. Though it got failed with below error.
<ShortMessage>Category is not valid.</ShortMessage>
<LongMessage>The category is not valid, select another category.</LongMessage>
<ErrorCode>107</ErrorCode>
<SeverityCode>Error</SeverityCode>
<ErrorClassification>RequestError</ErrorClassification>
Request message is
<?xml version="1.0" encoding="UTF-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>********PG1QKFIlH****</eBayAuthToken>
</RequesterCredentials>
<Version>967</Version>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>Sample ebay motor brake fitment product</Title>
<Description>Hummer Truck Right Side Mirror</Description>
<StartPrice currencyID="USD">236.0</StartPrice>
<Country>US</Country>
<Currency>USD</Currency>
<ListingDuration>Days_7</ListingDuration>
<Location>Los Angeles, California</Location>
<DispatchTimeMax>2</DispatchTimeMax>
<ConditionID>1000</ConditionID>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>w*****1#gmail.com</PayPalEmailAddress>
<Quantity>1</Quantity>
<PrimaryCategory>
<CategoryID>33562</CategoryID>
</PrimaryCategory>
<PictureDetails>
<GalleryType>Gallery</GalleryType>
<GalleryURL>http://****/z/QJsAAOSwXSJXPHk~/$_1.JPG?set_id=880000500F</GalleryURL>
<PhotoDisplay>PicturePack</PhotoDisplay>
<PictureURL>http://*****/z/QJsAAOSwXSJXPHk~/$_1.JPG?set_id=880000500F</PictureURL>
</PictureDetails>
<ShippingDetails>
<ApplyShippingDiscount>false</ApplyShippingDiscount>
<GlobalShipping>true</GlobalShipping>
<CalculatedShippingRate>
<WeightMajor measurementSystem="English" unit="lbs">0</WeightMajor>
<WeightMinor measurementSystem="English" unit="oz">0</WeightMinor>
</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingService>ShippingMethodStandard</ShippingService>
<ShippingServiceCost currencyID="USD">0.0</ShippingServiceCost>
<ShippingServicePriority>1</ShippingServicePriority>
<ExpeditedService>false</ExpeditedService>
<ShippingTimeMin>1</ShippingTimeMin>
<ShippingTimeMax>6</ShippingTimeMax>
<FreeShipping>true</FreeShipping>
</ShippingServiceOptions>
<ShippingType>Flat</ShippingType>
<ThirdPartyCheckout>false</ThirdPartyCheckout>
<TaxTable>
<TaxJurisdiction>
<JurisdictionID>CA</JurisdictionID>
<SalesTaxPercent>10.0</SalesTaxPercent>
<ShippingIncludedInTax>false</ShippingIncludedInTax>
</TaxJurisdiction>
</TaxTable>
<ShippingDiscountProfileID>0</ShippingDiscountProfileID>
<InternationalShippingDiscountProfileID>0</InternationalShippingDiscountProfileID>
<ExcludeShipToLocation>Alaska/Hawaii</ExcludeShipToLocation>
<ExcludeShipToLocation>US Protectorates</ExcludeShipToLocation>
<ExcludeShipToLocation>APO/FPO</ExcludeShipToLocation>
<ExcludeShipToLocation>Africa</ExcludeShipToLocation>
<ExcludeShipToLocation>Asia</ExcludeShipToLocation>
<ExcludeShipToLocation>Central America and Caribbean</ExcludeShipToLocation>
<ExcludeShipToLocation>Europe</ExcludeShipToLocation>
<ExcludeShipToLocation>Middle East</ExcludeShipToLocation>
<ExcludeShipToLocation>Oceania</ExcludeShipToLocation>
<ExcludeShipToLocation>Southeast Asia</ExcludeShipToLocation>
<ExcludeShipToLocation>South America</ExcludeShipToLocation>
<ExcludeShipToLocation>BM</ExcludeShipToLocation>
<ExcludeShipToLocation>GL</ExcludeShipToLocation>
<ExcludeShipToLocation>MX</ExcludeShipToLocation>
<ExcludeShipToLocation>PM</ExcludeShipToLocation>
<ExcludeShipToLocation>PO Box</ExcludeShipToLocation>
<SellerExcludeShipToLocationsPreference>true</SellerExcludeShipToLocationsPreference>
</ShippingDetails>
<ReturnPolicy>
<RefundOption>MoneyBack</RefundOption>
<Refund>Money Back</Refund>
<ReturnsWithinOption>Days_14</ReturnsWithinOption>
<ReturnsWithin>14 Days</ReturnsWithin>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<ReturnsAccepted>Returns Accepted</ReturnsAccepted>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
<ShippingCostPaidBy>Buyer</ShippingCostPaidBy>
<RestockingFeeValue>No</RestockingFeeValue>
<RestockingFeeValueOption>NoRestockingFee</RestockingFeeValueOption>
</ReturnPolicy>
<ItemCompatibilityList>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>2008</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Workhorse Custom Chassis</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>R26</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Motor Home - Stripped Chassis</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>8.1L 496Cu. In. V8 GAS OHV Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1998</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Advance Mixer</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>M</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Straight Truck - Half Cab</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>-- DIESEL</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1988</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Yugo</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>GVS</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Hatchback 3-Door</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>1.1L 1116CC l4 GAS SOHC Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1963</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Wolseley</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>1500</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>1.5L 1489CC 91Cu. In. l4 GAS OHV Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1928</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Yellow Cab</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>Model D-1</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>--</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
</ItemCompatibilityList>
</Item>
</AddItemRequest>

Make sure that you using the 100 as the value of the HTTP header X-EBAY-API-SITEID. This ensures that your request is routed to the eBay motors site where the category is valid. Using 0 in the header routes the request to ebay.com where the category is not valid.

Related

Parse xml file in pandas

I have this xml file (it's called "LogReg.xml" and it contains some information about a logistic regression (I am interested in the name of the features and their coefficient - I'll explain in more detail below):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PMML xmlns="http://www.dmg.org/PMML-4_4" xmlns:data="http://jpmml.org/jpmml-model/InlineTable" version="4.4">
<Header>
<Application name="JPMML-SkLearn" version="1.6.35"/>
<Timestamp>2022-02-15T09:44:54Z</Timestamp>
</Header>
<MiningBuildTask>
<Extension name="repr">PMMLPipeline(steps=[('classifier', LogisticRegression())])</Extension>
</MiningBuildTask>
<DataDictionary>
<DataField name="Target" optype="categorical" dataType="integer">
<Value value="0"/>
<Value value="1"/>
</DataField>
<DataField name="const" optype="continuous" dataType="double"/>
<DataField name="grade" optype="continuous" dataType="double"/>
<DataField name="emp_length" optype="continuous" dataType="double"/>
<DataField name="dti" optype="continuous" dataType="double"/>
<DataField name="Orig_FicoScore" optype="continuous" dataType="double"/>
<DataField name="inq_last_6mths" optype="continuous" dataType="double"/>
<DataField name="acc_open_past_24mths" optype="continuous" dataType="double"/>
<DataField name="mort_acc" optype="continuous" dataType="double"/>
<DataField name="mths_since_recent_bc" optype="continuous" dataType="double"/>
<DataField name="num_rev_tl_bal_gt_0" optype="continuous" dataType="double"/>
<DataField name="percent_bc_gt_75" optype="continuous" dataType="double"/>
</DataDictionary>
<RegressionModel functionName="classification" algorithmName="sklearn.linear_model._logistic.LogisticRegression" normalizationMethod="logit">
<MiningSchema>
<MiningField name="Target" usageType="target"/>
<MiningField name="const"/>
<MiningField name="grade"/>
<MiningField name="emp_length"/>
<MiningField name="dti"/>
<MiningField name="Orig_FicoScore"/>
<MiningField name="inq_last_6mths"/>
<MiningField name="acc_open_past_24mths"/>
<MiningField name="mort_acc"/>
<MiningField name="mths_since_recent_bc"/>
<MiningField name="num_rev_tl_bal_gt_0"/>
<MiningField name="percent_bc_gt_75"/>
</MiningSchema>
<Output>
<OutputField name="probability(0)" optype="continuous" dataType="double" feature="probability" value="0"/>
<OutputField name="probability(1)" optype="continuous" dataType="double" feature="probability" value="1"/>
</Output>
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
<RegressionTable intercept="0.0" targetCategory="0"/>
</RegressionModel>
</PMML>
I have parsed it using this code:
from lxml import objectify
path = 'LogReg.xml'
parsed = objectify.parse(open(path))
root = parsed.getroot()
data = []
if True:
for elt in root.RegressionModel.RegressionTable:
el_data = {}
for child in elt.getchildren():
el_data[child.tag] = child.text
data.append(el_data)
perf = pd.DataFrame(data)
I am interested in parsing this bit:
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
so that I can build the following dictionary:
myDict = {
"const : 0.8013433785974717,
"grade" : 0.9010481046582982,
"emp_length" : 0.9460686056314133,
"dti" : 0.5117062988491518,
"Orig_FicoScore" : 0.07944303372859234,
"inq_last_6mths" : 0.20516234445402765,
"acc_open_past_24mths" : 0.4852503249658917,
"mort_acc" : 0.6673203078463711,
"mths_since_recent_bc" : 0.1962158305958366,
"num_rev_tl_bal_gt_0" : 0.12964661294856686,
"percent_bc_gt_75" : 0.04534570018290847
}
Basically, in the dictionary the Key is the name of the feature and the value is the coefficient of the logistic regression.
Please can anyone help me with the code?
I'm not sure you need pandas for this, but you do need to handle the namespaces in your xml.
Try something along these lines:
myDict = {}
#register the namespace
ns = {'xx': 'http://www.dmg.org/PMML-4_4'}
#you could collapse the next two into one line, but I believe it's clearer this way
rt = root.xpath('//xx:RegressionTable[.//xx:NumericPredictor]',namespaces=ns)[0]
nps = rt.xpath('./xx:NumericPredictor',namespaces=ns)
for np in nps:
myDict[np.attrib['name']]=np.attrib['coefficient']
myDict
The output should be your expected output.

Merging using XSLT

Below is my input XML. Here Each X_DLV_TAB_ITEM have multiple RL_DETAILS that again have multiple RL_DETAILS_ITEM. Each X_DLV_TAB_ITEM contains TYPE.
My requirement is if TYPE is same for two or more X_DLV_TAB_ITEM then only one X_DLV_TAB_ITEM should get created which will contain all the RL_DETAILS_ITEM with same TYPE and for the ones with different TYPE need to follow the rest.
INPUT:
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>12</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460994</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>33</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.6</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>15</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689766</DELIVERY_ID>
<NAME>46689766</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>C</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689767</DELIVERY_ID>
<NAME>46689767</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>150</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
</X_DLV_TAB>
OUTPUT:
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460994</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>33</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.6</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>15</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>12</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689766</DELIVERY_ID>
<NAME>46689766</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>C</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689767</DELIVERY_ID>
<NAME>46689767</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>150</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
</X_DLV_TAB>
My Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="first_of_source" match="X_DLV_TAB/X_DLV_TAB_ITEM[not(preceding-sibling::X_DLV_TAB_ITEM/TYPE = TYPE)]" use="TYPE"/>
<xsl:key name="same_source" match="X_DLV_TAB/X_DLV_TAB_ITEM/RL_DETAILS" use="RL_DETAILS_ITEM"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="X_DLV_TAB">
<xsl:copy>
<xsl:apply-templates select="key('first_of_source', X_DLV_TAB_ITEM/TYPE)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RL_DETAILS">
<xsl:copy>
<xsl:apply-templates select="key('same_source', RL_DETAILS_ITEM)/RL_DETAILS_ITEM"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And this code is not generating the required output. I am using XSLT 1.0.
AFAICT, you want to do:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="item-by-type" match="X_DLV_TAB_ITEM" use="TYPE"/>
<xsl:template match="/X_DLV_TAB">
<xsl:copy>
<!-- create a group for each distinct TYPE -->
<xsl:for-each select="X_DLV_TAB_ITEM[count(. | key('item-by-type', TYPE)[1]) = 1]">
<xsl:copy>
<!-- copy common elements -->
<xsl:copy-of select="*[not(self::RL_DETAILS)]"/>
<RL_DETAILS>
<!-- copy all RL_DETAILS_ITEMs of current group-->
<xsl:copy-of select="key('item-by-type', TYPE)/RL_DETAILS/RL_DETAILS_ITEM"/>
</RL_DETAILS>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Note that this assumes that all X_DLV_TAB_ITEMs with the same TYPE have the same data, except for the contents of RL_DETAILS. Therefore, all data except the contents of RL_DETAILS is copied from the first X_DLV_TAB_ITEM of each group. Then the RL_DETAILS element is populated by the RL_DETAILS_ITEMs of the entire group.

Parse KML file with vba

I am trying to get 2 pieces of information from a KML file. I have some code (ref:K Buttters) in vba (as I want to add the data to a db). This code works perfectly and returns the coordinates, but I want to also get the data for the name tag. How do I amend the code to get this extra piece of information. information. Thanks
Public Sub readFile()
Dim objXML As MSXML2.DOMDocument60
Dim ns As String
Dim nodelist As IXMLDOMNodeList
Dim coordNode As IXMLDOMNode
Dim XPath As String
Dim Namespace As String
Dim i As Integer
'Create the DomDocument Object
'Set objXML = CreateObject("MSXML2.DOMDocument60")
Set objXML = New MSXML2.DOMDocument60
'Load entire Document before moving on
objXML.async = False
'Don't Validate
objXML.validateOnParse = False
'Read in the file
objXML.Load ("C:\pcsect2.kml")
''''''''''''''''''''''''''''''
' Set up the appropriate (default) namespace
''''''''''''''''''''''''''''''
Namespace = "xmlns:ns='http://www.opengis.net/kml/2.2'"
Call objXML.SetProperty("SelectionNamespaces", Namespace)
Call objXML.SetProperty("SelectionLanguage", "XPath")
''''''''''''''''''''''''''''''
' Define the XPath to get to coordinates
''''''''''''''''''''''''''''''
XPath = "//ns:coordinates"
''''''''''''''''''''''''''''''
' Select All "coordinates" nodes
''''''''''''''''''''''''''''''
Set nodelist = objXML.SelectNodes(XPath)
''''''''''''''''''''''''''''''
' Nodelist contains all the Coordinates...
' note: Under view ... set immediate window to viewable to see the debug.print results...
''''''''''''''''''''''''''''''
For i = 0 To nodelist.Length - 1
Set coordNode = nodelist.NextNode
Debug.Print coordNode.Text
Next i
End Sub
kml file:
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<description><![CDATA[UK postcode polygons]]></description>
<Style id="stylePostcode">
<LineStyle>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>00ff0000</color>
</PolyStyle>
</Style>
<Style id="stylePostcode" xmlns="http://www.opengis.net/kml/2.2">
<LineStyle>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>00ff0000</color>
</PolyStyle>
</Style>
<Folder xmlns="http://www.opengis.net/kml/2.2">
<name>AB10</name>
<description><![CDATA[Postcode sectors in the AB10 postcode district]]></description>
<Placemark>
<name>AB10 1</name>
<styleUrl>#stylePostcode</styleUrl>
<description><![CDATA[AB10 1 postcode sector]]></description>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-2.09646046762775,57.1512327554617 -2.0962834594401,57.1506128321186 -2.09610247782767
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-2.10596557515499,57.1385921418501 -2.10604057319705,57.1387481221535
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>AB10 6</name>
<styleUrl>#stylePostcode</styleUrl>
<description><![CDATA[AB10 6 postcode sector</a>]]></description>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-2.11311153246704,57.1365722876569 -2.11309853402536,57.1365692881912
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-2.1113360807897,57.1427795678869 -2.11112010338182,57.1426645845693
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>AB10 7</name>
<styleUrl>#stylePostcode</styleUrl>
<description><![CDATA[AB10 7 postcode sector>Details</a>]]></description>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-2.11383946866067,57.1372032022769 -2.11366248946505,57.1371542105275
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Folder>
<Style id="stylePostcode" xmlns="http://www.opengis.net/kml/2.2">
<LineStyle>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>00ff0000</color>
</PolyStyle>
</Style>
<Folder xmlns="http://www.opengis.net/kml/2.2">
<name>ZE3</name>
<description><![CDATA[Postcode sectors in the ZE3 postcode district]]></description>
<Placemark>
<name>ZE3 9</name>
<styleUrl>#stylePostcode</styleUrl>
<description><![CDATA[ZE3 9 postcode sector>Details</a>]]></description>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-1.33983120448744,59.8989006252828 -1.32301876923355,59.9016455421112
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-1.32885903137389,59.8719950412819 -1.33463302343859,59.8690613106313
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Folder>
</Document>
</kml>

Parsing XML by OpenXML with multiple Parent nodes with multiple child nodes

I have the following XML:
<Report>
<Accounts>
<Account>
<Currency>USD</Currency>
<AccountBalance>45555</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>502</PaymentCode>
<PaymentAmount currCode="GBP">7000.00000000</PaymentAmount>
</PaymentData>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
<Account>
<Currency>USD</Currency>
<AccountBalance>50000</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
</Accounts>
</Report>
My SQL Code is parsing this with the following code:
SELECT
[currCode] AS [Currency],
[AccountBalance] AS [AccountBalance],
[PaymentCode] AS [PaymentCode],
[PaymentCurrCode] AS [PaymentCurrCode],
[PaymentAmount] AS [PaymentAmount]
FROM OPENXML(#hDoc, 'Report/Accounts/Account',2)
WITH
(
[currCode] [nchar](3) 'currCode',
[AccountBalance] [decimal](18, 0) 'AccountBalance',
[PaymentCode] [nchar](10) 'Payments/PaymentData/PaymentCode',
[PaymentCurrCode] [nchar](3) 'Payments/PaymentData/PaymentAmount/#currCode',
[PaymentAmount] [decimal](18, 0) 'Payments/PaymentData/PaymentAmount'
)
I am getting the following result:
currCode | AccountBalance | PaymentCode | PaymentCurrCode | PaymentAmount
————————————————————————————————————————————————————————————————————————————————
USD | 45555 | 502 | GBP |7000.00000000
USD | 50000 | 501 | USD |5000.00000000
I am trying to get the multiple paymentdata and multiple account with the same openXml query. How Can is get all the data with the following result:
currCode | AccountBalance | PaymentCode | PaymentCurrCode | PaymentAmount
————————————————————————————————————————————————————————————————————————————————
USD | 45555 | 502 | GBP |7000.00000000
USD | 45555 | 501 | USD |5000.00000000
USD | 50000 | 501 | USD |5000.00000000
This is an up-to-date and state-of-the-art approach with XQuery/XPath methods. The result is the same, just faster and better to read:
DECLARE #XML XML=
'<Report>
<Accounts>
<Account>
<Currency>USD</Currency>
<AccountBalance>45555</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>502</PaymentCode>
<PaymentAmount currCode="GBP">7000.00000000</PaymentAmount>
</PaymentData>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
<Account>
<Currency>USD</Currency>
<AccountBalance>50000</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
</Accounts>
</Report>';
SELECT Payment.value('(../../Currency)[1]','nchar(3)') AS currCode
,Payment.value('(../../AccountBalance)[1]','decimal(18,0)') AS AccountBalance
,Payment.value('PaymentCode[1]','nchar(10)') AS PaymentCode
,Payment.value('PaymentAmount[1]/#currCode','nchar(3)') AS PaymentCurrCode
,Payment.value('PaymentAmount[1]','decimal(18,0)') AS PaymentCurrCode
FROM #XML.nodes('Report/Accounts/Account/Payments/PaymentData') AS One(Payment)
This should work for you:
DECLARE #XML XML=
'<Report>
<Accounts>
<Account>
<Currency>USD</Currency>
<AccountBalance>45555</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>502</PaymentCode>
<PaymentAmount currCode="GBP">7000.00000000</PaymentAmount>
</PaymentData>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
<Account>
<Currency>USD</Currency>
<AccountBalance>50000</AccountBalance>
<Payments>
<PaymentData>
<PaymentCode>501</PaymentCode>
<PaymentAmount currCode="USD">5000.00000000</PaymentAmount>
</PaymentData>
</Payments>
</Account>
</Accounts>
</Report>';
DECLARE #hDoc INT;
EXEC sp_xml_preparedocument #hDoc OUTPUT, #XML;
SELECT
[currCode] AS [Currency],
[AccountBalance] AS [AccountBalance],
[PaymentCode] AS [PaymentCode],
[PaymentCurrCode] AS [PaymentCurrCode],
[PaymentAmount] AS [PaymentAmount]
FROM OPENXML(#hDoc, 'Report/Accounts/Account/Payments/PaymentData',2)
WITH
(
[currCode] [nchar](3) '../../Currency',
[AccountBalance] [decimal](18, 0) '../../AccountBalance',
[PaymentCode] [nchar](10) 'PaymentCode',
[PaymentCurrCode] [nchar](3) 'PaymentAmount/#currCode',
[PaymentAmount] [decimal](18, 0) 'PaymentAmount'
)
EXEC sp_xml_removedocument #hDoc;

xml file data imported to sql with script

im having this kind of xml:
<?xml version="1.0"?>
-<recordedData>
<machine>ZSK40-2</machine>
<date>2013/09/21</date>
<hour>05:32</hour>-<CollectedData>-<variable>
<Name>PRODUCT</Name>
<Value>FILLER 580</Value>
</variable>-<variable>
<Name>LOT_NUMBER</Name>
<Value>CG 00063 0</Value>
</variable>-<variable>
<Name>SHIFT_SUPERVISOR</Name>
<Value> covaliu l</Value>
</variable>-<variable>
<Name>KGH_ALL_SET</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_ALL_REAL</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_F1_SET</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_F1_REAL</Name>
<Value>0</Value>
</variable>-<variable>
<Name>K_F1</Name>
<Value>43</Value>
</variable>-<variable>
<Name>SCREW_RPM_SET</Name>
<Value>550</Value>
</variable>-<variable>
<Name>SCREW_RPM_REAL</Name>
<Value>550.085388183594</Value>
</variable>-<variable>
<Name>TORQUE</Name>
<Value>1.21340000629425</Value>
</variable>-<variable>
<Name>CURRENT</Name>
<Value>60.1959991455078</Value>
</variable>-<variable>
<Name>KW_KG</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KW</Name>
<Value>-0.990000009536743</Value>
</variable>-<variable>
<Name>MELT_PRESSURE</Name>
<Value>0</Value>
</variable>-<variable>
<Name>MELT_TEMPERATURE</Name>
<Value>214</Value>
</variable>-<variable>
<Name>PV1</Name>
<Value>216</Value>
</variable>-<variable>
<Name>SP1</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV2</Name>
<Value>239</Value>
</variable>-<variable>
<Name>SP2</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV3</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP3</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV4</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP4</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV5</Name>
<Value>209</Value>
</variable>-<variable>
<Name>SP5</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV6</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP6</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV7</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP7</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV8</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP8</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV9</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP9</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV10</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP10</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV11</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP11</Name>
<Value>220</Value>
</variable>
</CollectedData>
</recordedData>
Can anyone provide a sample sql script for extracting all the data from it please.
i would really apreciate this since im new to xml.
Thanks in advance.
If you have your data in a table already, you can use something like this:
DECLARE #Tmp TABLE (ID INT NOT NULL, XmlContent XML)
INSERT INTO #TMP VALUES(1, '......(your entire XML here).......)
SELECT
ID,
MACHINE = XmlContent.value('(/recordedData/machine)[1]', 'varchar(50)'),
RecordingDate = XmlContent.value('(/recordedData/date)[1]', 'varchar(50)'),
RecordingTime = XmlContent.value('(/recordedData/hour)[1]', 'varchar(50)'),
VariableName = XVar.value('(Name)[1]', 'varchar(50)'),
VariableValue = XVar.value('(Value)[1]', 'varchar(50)')
FROM
#Tmp
CROSS APPLY
XmlContent.nodes('/recordedData/CollectedData/variable') AS XTbl(XVar)
This gives you an output something like:
.... and so on - listing all the variables with their name and value.