* wadia.prg -- read in wadia.xml and * output 2 cursors via XMLAdapter LOCAL oxa AS xmladapter oxa=CREATEOBJECT("xmladapter") * tell XMLAdapter we don't have a schema so it will * go ahead and load the XML anyway oxa.XMLSchemaLocation="" * load the XML oxa.LoadXML("wadia.xml",.T.) * now set up your own internal schema to tell * XMLAdapter where to find the tables and fields * * NOTE: You will have to add more XMLField * objects in the code to get all the fields * This code is just to show you how. * * NOTE: Tag names are case-sensitive * * NOTE: All XPath statements are relative to the * next-higher hierarchical level. The starting * point is the "root" tag, which in this case * is <TestCard> * CardMeta table oTable = CREATEOBJECT("XMLTable") * all XMLName properties must be Unicode oTable.XMLName = STRCONV("CardMeta",5) oTable.XMLNameIsXpath = .T. * the cursor's alias oTable.Alias = "cardmeta" oField = CREATEOBJECT("XMLField") oField.XMLName = STRCONV("DocId",5) oField.XMLNameIsXpath = .T. * field.alias means the field name you want * in your cursor oField.Alias = "docid" oField.DataType = "C" oField.MaxLength = 40 oTable.Fields.Add(oField, oField.XMLName) oField = CREATEOBJECT("XMLField") oField.XMLName = STRCONV("xeProjectNumber",5) oField.XMLNameIsXpath = .T. oField.Alias = "xeprojectnumber" oField.DataType = "C" oField.MaxLength = 4 oTable.Fields.Add(oField, oField.XMLName) *** You add more fields here for this table * add the first table to the tables collection oxa.Tables.Add(oTable, oTable.XMLName) * ABCFile table oTable = CREATEOBJECT("XMLTable") oTable.XMLName = STRCONV("ABCFiles/ABCFile",5) oTable.XMLNameIsXpath = .T. oTable.Alias = "abcfile" oField = CREATEOBJECT("XMLField") oField.XMLName = STRCONV("ApplicationClass",5) oField.XMLNameIsXpath = .T. * NOTE: Field names can be different from the * XML Tags oField.Alias = "appclass" oField.DataType = "C" oField.MaxLength = 3 oTable.Fields.Add(oField, oField.XMLName) oField = CREATEOBJECT("XMLField") oField.XMLName = STRCONV("FileName",5) oField.XMLNameIsXpath = .T. oField.Alias = "filename" * change data types if you like -- in this case, * why not Varchar(100)? oField.DataType = "V" oField.MaxLength = 100 oTable.Fields.Add(oField, oField.XMLName) oxa.Tables.Add(oTable, oTable.XMLName) * now output and browse the 2 cursors oxa.tables(1).toCursor() BROWSE oxa.tables(2).toCursor() BROWSE>Hi!
><?xml version="1.0" encoding="UTF-8" ?> ><TestCard> ><CardMeta> ><DocId>FEAE7D6117849755C1257066004D9E4C</DocId> ><xeProjectNumber>9876</xeProjectNumber> ><xeSubProjectNumber></xeSubProjectNumber> ><xeSubProjectDescription></xeSubProjectDescription> ><xeProjectName>Project test</xeProjectName> ><xeTitle1>testing</xeTitle1> ><xeTitle2></xeTitle2> ><xeTitle3></xeTitle3> ><xeTitle4></xeTitle4> ><xeTitle5></xeTitle5> ><xeSOPId>48-9876/A.01A/001/1A</xeSOPId> ><xeIndex>001</xeIndex> ><xeDisciplineCode>A</xeDisciplineCode> ><TestDescription>Art</TestDescription> ><xeTypeCode>01A</xeTypeCode> ><TypeDescription>testdetail</TypeDescription> ><ModifiedBy>usera</ModifiedBy> ><wfRevisionCode>1A</wfRevisionCode> ><wfRevisionSubject>ISSUED FOR test</wfRevisionSubject> ><StatusTitle>Approved by test</StatusTitle> ><Site>48</Site> ><SiteDescription></SiteDescription> ><xeClientNumber></xeClientNumber> ><ClientName>My Self</ClientName> ><Media>ELECTRONIC</Media> ></CardMeta> ><ABCFiles> ><ABCFile> ><ApplicationClass>Pdf</ApplicationClass> ><FileName>test1.pdf</FileName> ></ABCFile> ><ABCFile> ><ApplicationClass>Pdf</ApplicationClass> ><FileName>test2.pdf</FileName> ></ABCFile> ><ABCFile> ><ApplicationClass>Pdf</ApplicationClass> ><FileName>test3.pdf</FileName> ></ABCFile> ></ABCFiles> ></TestCard> >