Innov-AI
    Documentation | MentDB Weak Server
Parse a XML file and integrate row into a SQL Database

  • Method 1:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    	
    	xml load "keyId" "<data id=\"25\"><item>A</item><item>B</item><item>C</item></data>";
    
    	#Xml manager start to index 1;
    	-> "[A]" (xml select text "keyId" "/data/item[1]");
    	-> "[B]" (xml select text "keyId" "/data/item[2]");
    	-> "[C]" (xml select text "keyId" "/data/item[3]");
    
    	sql dml "session1" (concat "insert into products (id, name, quantity) values (" (sql encode [A]) ", " (sql encode [B]) ", " (sql encode [C]) ");");
    
    	sql disconnect "session1";
    
    } {
    
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
  • Method 2:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    
    	xml load "keyId" "<data id=\"25\"><item>A</item><item>B</item><item>C</item></data>";
    	-> "[nb_item]" (xml count "keyId" "/data/item");
    
    	#Xml manager start to index 1;
    	for (-> "[i_item]" 1) (<= [i_item] [nb_item]) (++ "[i_item]") {
    	
    		-> "[name]" (xml select text "keyId" (concat "/data/item[" [i_item] "]"));
    		
    		sql dml "session1" (concat "insert into products (id, name, quantity) values (" (sql encode [i_item]) ", " (sql encode [name]) ", 100);");
    	
    	};
    
    	sql disconnect "session1";
    
    } {
    
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
Services     Supporters     Contact     About     Legal notice © 2024