Developer forum

Forum » Development » Import from xml to database

Import from xml to database


Reply
Hi all,



I've been playing around for a bit now with the importing functionality of eCommerce, but I can't seem to get it right. So a little assistance would be nice ;-)



For testing purposes I have exported a file from the current eCommerce product database, and I  have an XML file now that has the following structure:









  PROD2

  LANG1

  SHOP1

 

  Adidas Ajax uitshirt 2007 / 2008  





  PROD3

  LANG1

 

 

  Adidas sporttas 







I have made an Import flow where the first block is a "XML file source" component with the following settings:



Root element = Root (what's this for anyway?)

XPath = //Product ( i want to have all products, could also have used /Products/Product )

Destination = /Filer/Integration/producten.xml



And the next block is "Product destination".



When I run this i get an error like:




4:28 PM Product destination Process Error: System.Xml.XmlException: Root element is missing. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at Dynamicweb.Integration.Specialized.ProductDestinationActivity.AddToQueue(XmlDocument xdoc) at Dynamicweb.Integration.Specialized.ProductDestinationActivity.Process()

4:28 PM Product destination Process Error: System.Xml.XmlException: Root element is missing. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at Dynamicweb.Integration.Specialized.ProductDestinationActivity.AddToQueue(XmlDocument xdoc) at Dynamicweb.Integration.Specialized.ProductDestinationActivity.Process()







Curious as I am, i replaced the "Product destination" box with a "Local file destination" box to see what data is constructed. Surprisingly, the configured "Root element" at the "XML file source" box is inserted in the XML structure as a parentnode of each (!) product.



So the xml looks like this:







  PROD2

  LANG1

  SHOP1

 

  Adidas Ajax uitshirt 2007 / 2008









  PROD3

  LANG1

 

 

  Adidas sporttas







Is this normal behaviour? or am I missing something, and how would I go from here to get the products imported?



-Emil



Replies

 
Reply
Hi,

As I understand, you try to import the following data:







  PROD2

  LANG1

  SHOP1

 

  Adidas Ajax uitshirt 2007 / 2008  





  PROD3

  LANG1

 

 

  Adidas sporttas 





You've added pipeline with two blocks: "XML file source" and "Product destination" - everything is right. Next, you've to set import parameters for pipeline blocks.

Root element - is the root node in your import XML for data to import. In your case its the "Products". So, set "Root element=Products".

XPath - should contain the xpath to the product's element node. Set it to //Products/Product for your input file.

File - virtual path to your file with products.

Try to set import parameters to the values above. I hope it will help.

Vitaly.
 
Reply
At first I had root element set to "Products" but the only difference is that adds a parent node named after the root element (Products) to the target XML.



So if I set root element to "Test" in the XML File source pipeline i get the following in the destination file:







  PROD2

  LANG1

  SHOP1

 

  Adidas Ajax uitshirt 2007 / 2008







   

      PROD3

      LANG1

     

     

      Adidas sporttas

   








In my opinion the above XML is not correct, because it doesn't have a root element. And that's also the error msg that application is complaining about. ( see first post )
 
Reply













  PROD2



  LANG1



  SHOP1



 



  Adidas Ajax uitshirt 2007 / 2008  











  PROD3



  LANG1



 



 



  Adidas sporttas 















I have made an Import flow where the first block is a "XML file source" component with the following settings:







Root element = Products



XPath = //Products/Product



File = /Filer/Integration/producten.xml This is where you get the products from



Then you need to put a destination group... If you haven't set it in you XML-data.



------


Above I wrote the settings that fit the data you are trying to import.



You seem to be a bit confused about what a Root element is. In a XML-document you can only have one root-element. Meaning in this case that all your xml-data must be inside these tags: 



And for each product you have inside the  tags, you will need to have around every products data.



But if you are new to XMLyou could invest in a good book about it.. I myself just started on xml 2 weeks ago, and by reading "XSLT for dummies" i managede to transform xml-data from an economy-system to xml-data that eCom understands and imports nicely.


When you read this book you get the understanding of the XML structure, and how to use XSLT to transform data from one structure to another.



all the best,


Jacob


 
Reply
Hi Jacob,



I'm well aware of what a Root element is, i'm just trying to show you that the Root element you have to configure in the XML File Source pipeline does not work as expected. ;-)



Even if I set it to "Products" (as one would expect), the XML in the destination file is modified to:





   

    ...

   






   

    ...

   








Notice that the XML document now does not have a root element?





Besides that, I'm not sure why one would have to specify a root element in the first place, because you can always make your selections by XPath.





For example: If I set the XPath property to "//Products" then it should match any Product node or I could use "/Products/Product" to make sure it's a Product node under the Products node.





Does anyone have a working import configuration with an "XML source file" and a "product destination" ? If so could you post its configuration here pls?





Regards,

Emil
 
Reply
Hi Emil,



Ok, when that's setteled, the settings I highlited in the previous post is working for me (Standard pipeline from Dynamicweb, only the server-path to the sourcefile is modyfied).

My source XML-document looks like this (When it's been parsed by my XSLT stylesheet):

http://www.kirk-holm.dk/Files/filer/Example.xml



But how do you see the result in the "destination file"?? If you import from an XML-document directly to a product destination (group in eCom), you dont' get a destination file, it's just put into the db??


 
Reply
Hi Jacob,







Thanks for your example file.







I will definitely try and use your XML file with the right settings.







How i get the results to a file? Well that's quite easy; if you remove the "product destination" and replace it with a "Local file destination" and then run it you get to see the xml.







Regards,



Emil
 
Reply
Emil Muller wrote:

Hi Jacob,















Thanks for your example file.















I will definitely try and use your XML file with the right settings.















How i get the results to a file? Well that's quite easy; if you remove the "product destination" and replace it with a "Local file destination" and then run it you get to see the xml.















Regards,







Emil
Perfect,



When you use my example-fil, remember to use a "product destination" BUT do not set any target groups. The target group is defined for each product in my XML-example... :-)

 

You must be logged in to post in the forum