Welcome! Log In Create A New Profile

Advanced

XMLtoTable

Posted by King 
King
XMLtoTable
October 18, 2009 09:20AM
Windev should consider to provide an XLMToTable function so that I don't need to write this as a workaround.

See below:

// 14:16:38 Fri 9 Oct 2009 xml2memoryTable
// 14:44:51 Sat 10 Oct 2009

XMLDoc is string="XML"
XMLInfo is string
sXmlTable is string = "C:\1.xml"
sTableName is string
sDir is string=completeDir("c:\wd7\7") //Make your own DIR
sFile is string="dTable"

HCancelDeclaration(dTable)
TableDesc is file description
ItemDesc is item description
dTable is data source
fDelete(sFile+".fic")
fDelete(sFile+".ndx")
hDuplicateKey is int = 2062 //2061 for hUniqueKey
nSize is int = 40

// Description of the "dTable" file
TableDesc..Name = "dTable"
TableDesc..Type = hFileNormal
TableDesc..FicCryptMethod = hCryptStandard


XMLClose(XMLDoc) //Frees the XML document

// Load the XML file in a string
XMLInfo = fLoadText(sXmlTable)
// Initialize the XML functions on this file
XMLDocument(XMLDoc,XMLInfo)
// point to the root
XMLRoot(XMLDoc)
XMLFind(XMLDoc, null)
sTableName = XMLElementName(XMLDoc)
//trace("ParentName"+nElement+"="+ XMLElementName(XMLDoc) )

XMLChild(XMLDoc)
XMLFirst(XMLDoc)

//trace("elementName"+nElement+"="+ XMLElementName(XMLDoc) )
ItemDesc..Name = XMLElementName(XMLDoc)
ItemDesc..Type = hItemText
ItemDesc..Size = nSize
ItemDesc..KeyType = hDuplicateKey

HDescribeItem ( TableDesc , ItemDesc )

nElement is int = 1
XMLNext(XMLDoc)
WHILE NOT XMLOut(XMLDoc)
nElement = nElement + 1
ItemDesc..Name = XMLElementName(XMLDoc)
ItemDesc..Type = hItemText
ItemDesc..Size = nSize
HDescribeItem ( TableDesc , ItemDesc )
// trace("elementName"+nElement+"="+ XMLElementName(XMLDoc) )
XMLNext(XMLDoc)
END

HDeclareExternal(sDir+sFile+".fic", sFile)
HDescribeFile ( TableDesc )
HImportXML ( dTable , sXmlTable , hImpCreation )
//Make a DUMMY Memory table, a few columns will do, mine is a 3-column table
OpenChild("t=c:\wd7\wdw\t03.wdw")

BuildBrowsingTable("t.tbl", sFile,taFillTable) //t.tbl WDWname.TableName
HCancelDeclaration(sFile)
HClose(dTable)

//trace("Total # of Elements in "+ sTableName + " = " + nElement)
// Cancels the search for the other XML functions used thereafter

XMLCancelSearch(XMLDoc)
XMLClose(XMLDoc) //Frees the XML document
Renko
Re: XMLtoTable
May 18, 2010 05:02PM
There is a simple way to import an xml to a table availeble.


sFile is string

// Opens the file picker
sFile = fSelect(SysDir, "", "Select a file...", "xml import" + TAB + "*.xml", "*.xml")


HImportXML(Producten,sFile,"","",hImpCreation,"")



TableDisplay(TABLE_Producten)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: