472,354 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

E4X XML creation and xmlns in nested elements: help request

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:

Expand|Select|Wrap|Line Numbers
  1. <store
  2.     xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  3. <product sku="10050-1653" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  4.     <sku>10050-1653</sku>
  5.     <name xml:lang="x-default">shop's Foie Gras</name>
  6.     <online>1</online>
  7.     <manufacturer>
  8.         <manufacturer-name>shop's</manufacturer-name>
  9.     </manufacturer>
  10.     <product-list-prices>
  11.         <product-list-price currency="USD">95</product-list-price>
  12.     </product-list-prices>
  13.     <variations>
  14.      <mastered-products>
  15.             <mastered-product default="1" sku="10050-1652"/>
  16.             <mastered-product sku="10050-1653"/>
  17.         </mastered-products>
  18.         <variation-attributes>
  19.             <variation-attribute name="Size">
  20.                 <custom-attributes>
  21.                     <custom-attribute name="displayName" type="string" xml:lang="x-default">Size</custom-attribute>
  22.                 </custom-attributes>
  23.             </variation-attribute>
  24.         </variation-attributes>
  25.     </variations>
  26.     <custom-attributes>
  27.         <custom-attribute name="Item_Ship_Weight" type="double" xml:lang="x-default">1.25</custom-attribute>
  28.         <custom-attribute name="Size" type="string" xml:lang="x-default"> 14 oz. no tin</custom-attribute>
  29.     </custom-attributes>
  30. </product>
  31. </store>
That is what the output XML should look like

This is what my ouput looks like

Expand|Select|Wrap|Line Numbers
  1. <store xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  2.     <product sku="1110001" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  3.         <sku>1110001</sku>
  4.     <ProductName>shop's Special Blend Coffee</ProductName>
  5. <long-description>Our TESTING house blend and our customers favorite. Full-bodied, flavorful - a perfect all around blend.</long-description>
  6.    <online>1</online>
  7. <manufacturer>
  8. <manufacturer-name>shops</manufacturer-name>
  9. </manufacturer>
  10. <product-list-prices>
  11. <Amount>6.98</Amount>
  12. <product-list-price currency="USD"/>
  13. </product-list-prices>
  14. <custom-attributes xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  15. <custom-attribute name="PID_VALUE_ManufacturerID@global" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">60100</custom-attribute>
  16. <custom-attribute name="LegacyItemNumber" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">60100</custom-attribute>
  17. <custom-attribute name="InStoreOnly" type="string" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">N</custom-attribute>
  18. <custom-attribute type="string" name="Grind" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  19. <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>
  20. </custom-attributes>
  21. <variations xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  22. <variation-attributes xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  23. <variation-attribute xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  24. <custom-attributes>
  25. <custom-attribute name="displayName" string="string">Grind</custom-attribute>
  26. </custom-attributes>
  27. </variation-attribute>
  28.  </variation-attributes>
  29. <mastered-products xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
  30.  <mastered-product sku="1110001-001" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  31.        <mastered-product sku="1110001-002" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  32.       <mastered-product sku="1110001-003" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  33.         <mastered-product sku="1110001-004" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  34.         <mastered-product sku="1110001-005" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog"/>
  35.       </mastered-products>
  36.     </variations>
  37. </product>
  38. </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:

Expand|Select|Wrap|Line Numbers
  1. var finalDWCatalogXML;
  2.     var productArrayList = new java.util.ArrayList();
  3.  
  4.     // pull the itemData out of the WIRXML for looping
  5.     var defaultNS = new Namespace('http://www.store.com/xml/1.1.0.0/impex/catalog');
  6.     default xml namespace = defaultNS;
  7.  
  8.     // start the DW catalog XML
  9.     finalDWCatalogXML = new XML('<store></store>');
  10.  
  11.     // Traverse the WIRXML item data
  12.     for(i in WIRItemData)
  13.     {
  14.         item = new XML(WIRItemData[i]);
  15.         productXMLHash = getProductAttributes(item);
  16. finalDWCatalogXML.appendChild(productXMLHash.get("masterProductXML"));
  17.  
  18.     } // close i WIRItemData loop
  19.  
  20.     print("finalDWCatalogXML = " + finalDWCatalogXML.toString());
  21.  
  22.     var exportString = finalDWCatalogXML.toString();
  23.  
  24.     return PIPELET_NEXT;
  25.  
  26.  
  27.  
  28. // ---------------------------------------------------------------------------------------
  29. // ---------------------------------------------------------------------------------------
  30.  
  31. function getProductAttributes(inXML)
  32. {
  33.     var finalOutputHash;
  34.     var productOutputXML = <product></product>;
  35.  
  36.     // sku
  37.     if(inXML.@itemCode != "")
  38.     {
  39.         productOutputXML.@sku = inXML.@itemCode;
  40.         productOutputXML.sku = inXML.@itemCode;
  41.     }
  42.  
  43.     // name
  44.     if(inXML.ProductName != "")
  45.     {
  46.         productOutputXML['name'] = inXML.ProductName;
  47.     }
  48.  
  49.     // long-description
  50.     if(inXML.InfoText.toString() != "")
  51.     {
  52.         productOutputXML['long-description'] = inXML.InfoText.toString();
  53.     }
  54.  
  55.     if(inXML.@isTaxable != "")
  56.     {
  57.         if(inXML.@isTaxable == "True")
  58.             productOutputXML['tax-class'].@id = "FullTax";
  59.         else
  60.             productOutputXML['tax-class'].@id = "NoTax";
  61.     }
  62.  
  63.     if(inXML.AttributeData.Attribute.(@name == "Brand").toString() != "")
  64.     {
  65.         productOutputXML.brand = inXML.AttributeData.Attribute.(@name == "Brand").toString();
  66.         productOutputXML.manufacturer['manufacturer-name'] = inXML.AttributeData.Attribute.(@name == "Brand").toString();
  67.     }
  68.  
  69.  
  70.     if(inXML.PriceData.Price.Amount != "")
  71.     {
  72.         productOutputXML['product-list-prices']['product-list-price'] = inXML.PriceData.Price.Amount;
  73.         productOutputXML['product-list-prices']['product-list-price'].@currency = "USD";
  74.     }
  75.  
  76.     // custom attributes
  77.     var customAttributesXML = <custom-attributes></custom-attributes>;
  78.  
  79.     if(inXML.AttributeData.Attribute.(@name == "Legacy Product ID").toString() != "")
  80.     {
  81.         customAttributesXML['custom-attribute'] += <custom-attribute name="PID_VALUE_ManufacturerID@global" type="string">{inXML.AttributeData.Attribute.(@name == "Legacy Product ID").toString()}</custom-attribute>;
  82.     }
  83. ...
  84.  
  85.     if(inXML.AttributeData.Attribute.(@name == "Regular Price").toString() != "")
  86.     {
  87.         customAttributesXML['custom-attribute'] += <custom-attribute name="RegularPrice" type="double">{inXML.AttributeData.Attribute.(@name == "Regular Price").toString()}</custom-attribute>;
  88.     }
  89.  
  90.  
  91.     var variationsXML = <variations></variations>;
  92.     var variationAttributesXML = <variation-attributes></variation-attributes>;
  93.     var variationCustomAttributesXML = <custom-attributes></custom-attributes>;
  94.  
  95.     for(j in inXML.DimensionData.Dimension)
  96.     {
  97.         dimensionXML = inXML.DimensionData.Dimension[j];
  98.  
  99.         variationAttributesXML['variation-attribute'] += <variation-attribute><custom-attributes><custom-attribute name = "displayName" string = "string">{dimensionXML.@name.toString()}</custom-attribute></custom-attributes></variation-attribute>
  100.     }
  101.  
  102.     variationsXML.appendChild(variationAttributesXML);
  103.  
  104.     var masteredProductsXML = <mastered-products></mastered-products>;
  105.     var masteredProductXML;
  106.  
  107.     for(x in inXML.SubItem)
  108.     {
  109.         subItemXML = inXML.SubItem[x];
  110.         masteredProductsXML['mastered-product'] += <mastered-product sku={subItemXML.@itemCode}></mastered-product>;
  111.  
  112.  
  113.     }
  114.  
  115.  
  116.     variationsXML.appendChild(masteredProductsXML);
  117.     productOutputXML.appendChild(variationsXML);
  118.     productOutputXML.appendChild(customAttributesXML);
  119.     finalOutputHash    = new java.util.HashMap();
  120.     finalOutputHash.put("masterProductXML" , productOutputXML);
  121.  
  122.     return finalOutputHash;
  123. }
Aug 31 '06 #1
0 2699

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bob Smith | last post by:
hi all, I pretty new to xml, what does xmlns mean? like in: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"...
1
by: jorgen.wahlund | last post by:
Hi I have problems with transforming a xml document with Xalan and javax.xml.Transformer. Following xsl is used: <xsl:stylesheet version='1.0'...
5
by: Tappy Tibbons | last post by:
I have a class I am serializing, and need the resultant XML to skip/omit classes that are not initialized, or their member variables have not been set. Is this possible? Say for the following...
4
by: Shailendra Batham | last post by:
Hi guys,Does any1 know what this error is all about, what I am trying to do is deserialize a XML, below is my code, let me know what I am doing wrongpublic class test{xin = "<?xml version='1.0'...
6
by: fzhang | last post by:
I am relatively new to XML and C#. So, forgive me if this question is too newbie. :-) While assuming this is an easy programming task, I couldn't find a single reference anywhere for how to do...
0
by: Ralfeus | last post by:
Hi all I'm too newbie in web services so I can't figure out what the error I made. I have a SOAP server written in PHP: <?php // Define the method as a PHP function function hello($name) {...
2
by: eliasen | last post by:
Hi I need to integrate to a system that has XML like this: <Calls xmlns="\\SomeMachine\Share\Schemas\Calls1_2.dtd" Version="1.2"> <Call> <CallRef>Call1</CallRef> <UserRef>286</UserRef>...
3
by: RK | last post by:
Is there an image handling guru out there than can help a newbie with understanding dynamic image creation? The question: I can create an image from within Javascript with MyPic = new Image()...
6
Dormilich
by: Dormilich | last post by:
Hi, I have some problems removing the xmlns attributes from a transformed xml file. I can't completely remove them (so it would validate). the problematic elements are <div> or the elements...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.