Expand|Select|Wrap|Line Numbers
- <store
- xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <product sku="10050-1653" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <sku>10050-1653</sku>
- <name xml:lang="x-default">shop's Foie Gras</name>
- <online>1</online>
- <manufacturer>
- <manufacturer-name>shop's</manufacturer-name>
- </manufacturer>
- <product-list-prices>
- <product-list-price currency="USD">95</product-list-price>
- </product-list-prices>
- <variations>
- <mastered-products>
- <mastered-product default="1" sku="10050-1652"/>
- <mastered-product sku="10050-1653"/>
- </mastered-products>
- <variation-attributes>
- <variation-attribute name="Size">
- <custom-attributes>
- <custom-attribute name="displayName" type="string" xml:lang="x-default">Size</custom-attribute>
- </custom-attributes>
- </variation-attribute>
- </variation-attributes>
- </variations>
- <custom-attributes>
- <custom-attribute name="Item_Ship_Weight" type="double" xml:lang="x-default">1.25</custom-attribute>
- <custom-attribute name="Size" type="string" xml:lang="x-default"> 14 oz. no tin</custom-attribute>
- </custom-attributes>
- </product>
- </store>
This is what my ouput looks like
Expand|Select|Wrap|Line Numbers
- <store xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <product sku="1110001" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <sku>1110001</sku>
- <ProductName>shop's Special Blend Coffee</ProductName>
- <long-description>Our TESTING house blend and our customers favorite. Full-bodied, flavorful - a perfect all around blend.</long-description>
- <online>1</online>
- <manufacturer>
- <manufacturer-name>shops</manufacturer-name>
- </manufacturer>
- <product-list-prices>
- <Amount>6.98</Amount>
- <product-list-price currency="USD"/>
- </product-list-prices>
- <custom-attributes xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <custom-attribute name="PID_VALUE_ManufacturerID@global" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">60100</custom-attribute>
- <custom-attribute name="LegacyItemNumber" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">60100</custom-attribute>
- <custom-attribute name="InStoreOnly" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">N</custom-attribute>
- <custom-attribute type="string" name="Grind" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- <custom-attribute name="HTMLDescription" type="html" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">Our TESTING house blend and our customers favorite. Full-bodied, flavorful - a perfect all around blend.</custom-attribute>
- </custom-attributes>
- <variations xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <variation-attributes xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <variation-attribute xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <custom-attributes>
- <custom-attribute name="displayName" string="string">Grind</custom-attribute>
- </custom-attributes>
- </variation-attribute>
- </variation-attributes>
- <mastered-products xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
- <mastered-product sku="1110001-001" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- <mastered-product sku="1110001-002" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- <mastered-product sku="1110001-003" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- <mastered-product sku="1110001-004" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- <mastered-product sku="1110001-005" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
- </mastered-products>
- </variations>
- </product>
- </store>
What I can tell is that in my code I am creating new xml elements to deal with the custom-attributes because it is a list and I do not know any other way to do it. It seems when ever I create new XML instead of build off of the main XML I get the NS set.
So my questions are:
1. How do I build multiple levels deep of lists in another way than I have done in my code? (see the :
var customAttributesXML = <custom-attributes></custom-attributes>;
and the variations section below it, which is nest 3 times.
section of the code)
2. Is there a way to "unset" the xmlns for particular elements of the XML.
This is all in the Rhino JS engine.
My code is below:
Expand|Select|Wrap|Line Numbers
- var finalDWCatalogXML;
- var productArrayList = new java.util.ArrayList();
- // pull the itemData out of the WIRXML for looping
- var defaultNS = new Namespace('http://www.store.com/xml/1.1.0.0/impex/catalog');
- default xml namespace = defaultNS;
- // start the DW catalog XML
- finalDWCatalogXML = new XML('<store></store>');
- // Traverse the WIRXML item data
- for(i in WIRItemData)
- {
- item = new XML(WIRItemData[i]);
- productXMLHash = getProductAttributes(item);
- finalDWCatalogXML.appendChild(productXMLHash.get("masterProductXML"));
- } // close i WIRItemData loop
- print("finalDWCatalogXML = " + finalDWCatalogXML.toString());
- var exportString = finalDWCatalogXML.toString();
- return PIPELET_NEXT;
- // ---------------------------------------------------------------------------------------
- // ---------------------------------------------------------------------------------------
- function getProductAttributes(inXML)
- {
- var finalOutputHash;
- var productOutputXML = <product></product>;
- // sku
- if(inXML.@itemCode != "")
- {
- productOutputXML.@sku = inXML.@itemCode;
- productOutputXML.sku = inXML.@itemCode;
- }
- // name
- if(inXML.ProductName != "")
- {
- productOutputXML['name'] = inXML.ProductName;
- }
- // long-description
- if(inXML.InfoText.toString() != "")
- {
- productOutputXML['long-description'] = inXML.InfoText.toString();
- }
- if(inXML.@isTaxable != "")
- {
- if(inXML.@isTaxable == "True")
- productOutputXML['tax-class'].@id = "FullTax";
- else
- productOutputXML['tax-class'].@id = "NoTax";
- }
- if(inXML.AttributeData.Attribute.(@name == "Brand").toString() != "")
- {
- productOutputXML.brand = inXML.AttributeData.Attribute.(@name == "Brand").toString();
- productOutputXML.manufacturer['manufacturer-name'] = inXML.AttributeData.Attribute.(@name == "Brand").toString();
- }
- if(inXML.PriceData.Price.Amount != "")
- {
- productOutputXML['product-list-prices']['product-list-price'] = inXML.PriceData.Price.Amount;
- productOutputXML['product-list-prices']['product-list-price'].@currency = "USD";
- }
- // custom attributes
- var customAttributesXML = <custom-attributes></custom-attributes>;
- if(inXML.AttributeData.Attribute.(@name == "Legacy Product ID").toString() != "")
- {
- customAttributesXML['custom-attribute'] += <custom-attribute name="PID_VALUE_ManufacturerID@global" type="string">{inXML.AttributeData.Attribute.(@name == "Legacy Product ID").toString()}</custom-attribute>;
- }
- ...
- if(inXML.AttributeData.Attribute.(@name == "Regular Price").toString() != "")
- {
- customAttributesXML['custom-attribute'] += <custom-attribute name="RegularPrice" type="double">{inXML.AttributeData.Attribute.(@name == "Regular Price").toString()}</custom-attribute>;
- }
- var variationsXML = <variations></variations>;
- var variationAttributesXML = <variation-attributes></variation-attributes>;
- var variationCustomAttributesXML = <custom-attributes></custom-attributes>;
- for(j in inXML.DimensionData.Dimension)
- {
- dimensionXML = inXML.DimensionData.Dimension[j];
- variationAttributesXML['variation-attribute'] += <variation-attribute><custom-attributes><custom-attribute name = "displayName" string = "string">{dimensionXML.@name.toString()}</custom-attribute></custom-attributes></variation-attribute>
- }
- variationsXML.appendChild(variationAttributesXML);
- var masteredProductsXML = <mastered-products></mastered-products>;
- var masteredProductXML;
- for(x in inXML.SubItem)
- {
- subItemXML = inXML.SubItem[x];
- masteredProductsXML['mastered-product'] += <mastered-product sku={subItemXML.@itemCode}></mastered-product>;
- }
- variationsXML.appendChild(masteredProductsXML);
- productOutputXML.appendChild(variationsXML);
- productOutputXML.appendChild(customAttributesXML);
- finalOutputHash = new java.util.HashMap();
- finalOutputHash.put("masterProductXML" , productOutputXML);
- return finalOutputHash;
- }