473,574 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

E4X XML creation and xmlns in nested elements: help request

1 New Member
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 customAttribute sXML = <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 2782

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

Similar topics

8
1899
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/" xmlns:perljobs="http://jobs.perl.org/rss/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/"...
1
5396
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' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xalan="http://xml.apache.org/xslt" xmlns:java="java"
5
2312
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 code, sometimes the Person may not have given us one, both, or either of their addresses. The serialize function will still put in a...
4
59249
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' encoding='UTF-8'?><InSession><PassWord>foo</PassWord><UserName>foo@foo.com</UserName></InSession>";XmlSerializer serializer = new...
6
24470
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 it. Here is the situation: I am given an XML file like the one below from other group in my company to load the data into our database. <root...
0
1595
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) { return 'Hello, ' . $name; }
2
2216
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> <Details> <Condition>EDITTABLE</Condition> <CallType>Water Damage</CallType>
3
2879
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() ....and then assign a source with MyPic.src = "./picture.gif";
6
5435
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 pasted by <xsl:copy-of> if I have no default NS in the XSL file I get the namespace attribute attached to the copied elements (the one from the "plan"...
0
7815
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8077
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7828
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6476
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3765
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.