Topic
  • 1 reply
  • Latest Post - ‏2012-12-10T23:48:46Z by SystemAdmin
BJordan
BJordan
25 Posts

Pinned topic Import catalog items from xml file

‏2012-12-08T14:40:22Z |
Hi,

I'm trying to import some data from xml file into pim using scripting api.

Problem: i can't make my import work :(

Scenario:


var xmlDoc = 

new XmlDocument(in); forEachXMLNode(xmlDoc, 
"export", node) 
{ forEachXMLNode(xmlDoc, 
"e", node) 
{ var item = 

new CtgItem(ctg); forEachXMLNode(xmlDoc, 
"a", node) 
{   var node = parseXMLNode(
"node"); var value = parseXMLNode(
"value"); item.setEntryAttrib(node, value); 
} item.saveCtgItem(); 
} 
}


XML sample:

<?xml version=
"1.0" encoding=
"UTF-8"?> <export> <e> <a> <node>Spec/att1</node> <value>47003316</value> </a> <a> <node>Spec/att2</node> <value>val2</value> </a> <a> <node>Spec/att3</node> <value>val3</value> </a> </e> </export>


I've getting an exception:

2012-12-08 17:17:26,117 [sch_worker_0] ERROR com.ibm.ccd.common.error.AustinException JOB_ID:9202- CWPCM0002E:Generic error / Exception: Script execution failed (java.lang.NullPointerException) Exception:java.lang.NullPointerException at com.ibm.ccd.common.interpreter.operation.generated.GenNewXmlDocumentOperation.execute(Unknown Source) at WPCImport13549762460130.run(WPCImport13549762460130.java:36) at com.ibm.ccd.common.interpreter.engine.Script.runFunction(Unknown Source) at com.ibm.ccd.common.interpreter.engine.Script.execute(Unknown Source) at com.ibm.ccd.common.interpreter.engine.Script.run(Unknown Source) at com.ibm.ccd.connectivity.common.DataImporter.importCatalog(Unknown Source) at com.ibm.ccd.connectivity.common.CtgToDb.execute(Unknown Source) at com.ibm.ccd.scheduler.threads.SchedulerThread.fuzaoRun(Unknown Source) at com.ibm.ccd.common.util.FuzaoRunnableAdapter.run(Unknown Source) at com.ibm.ccd.common.util.FuzaoThread.run(Unknown Source) , Exception:java.lang.NullPointerException at com.ibm.ccd.common.interpreter.operation.generated.GenNewXmlDocumentOperation.execute(Unknown Source) at WPCImport13549762460130.run(WPCImport13549762460130.java:36) at com.ibm.ccd.common.interpreter.engine.Script.runFunction(Unknown Source) at com.ibm.ccd.common.interpreter.engine.Script.execute(Unknown Source) at com.ibm.ccd.common.interpreter.engine.Script.run(Unknown Source) at com.ibm.ccd.connectivity.common.DataImporter.importCatalog(Unknown Source) at com.ibm.ccd.connectivity.common.CtgToDb.execute(Unknown Source) at com.ibm.ccd.scheduler.threads.SchedulerThread.fuzaoRun(Unknown Source) at com.ibm.ccd.common.util.FuzaoRunnableAdapter.run(Unknown Source) at com.ibm.ccd.common.util.FuzaoThread.run(Unknown Source)


E.g., looks like it just can't create xml document at all...

Any working samples of xml import would be greatly appreciated...
Updated on 2012-12-10T23:48:46Z at 2012-12-10T23:48:46Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: Import catalog items from xml file

    ‏2012-12-10T23:48:46Z  
    Hi BJordan!

    Reading from InfoCenter:

    new$XmlDocument script operation
    Creates an XmlDocument from a docstore Doc instance or an XML string literal.
    Syntax
    new XmlDocument(Doc doc/String str)

    That means that you can't use the in variable as an argument, because that's neither a Doc nor a String.

    Here's a catalog import script that uses a docstore Doc for creating the XmlDocument and works with your XML sample.

    
    var doc = getDocByPath(feed_doc_path); var xmlDoc = 
    
    new XmlDocument(doc); forEachXMLNode(xmlDoc, 
    "e", enode) 
    { var item = 
    
    new CtgItem(ctg); forEachXMLNode(enode, 
    "a", anode) 
    { var node = anode.getXMLNodeValue(
    "node"); var value = anode.getXMLNodeValue(
    "value"); item.setEntryAttrib(node, value); 
    } item.saveCtgItem(); 
    }
    

    Regards,
    Kaisa