I am trying to create a large nested XML object using E4X methods. The problem is the, the XML I am trying to create can only have xmlns set at the top 2 element levels. Such as:
- <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>
That is what the output XML should look like
This is what my ouput looks like
- <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>
Now forget that some of these values don't 100% map up, the real problem I am having is with the xmlns. I do not want it set at the levels it is being set at, I only want it set for the top 2 levels. The main store element and the product elements under it.
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: