Mallikarjun Gudidevuni
11/11/2005 10:36:00 AM
Hi Lennart Conrad,
I am very thank full to u. I have tied using XMLDocument class and
Writing the XML data into a text file.
It will be grate plesure if u send a sample code.
Here is my code
// Changed on 09 Nov 2005 at 07:59:49 by Malik
static void XMLDataImp(Args _args)
{
str filename, nodeName,txtFile,strTxtRow;
str AttName;
int i,j,k;
boolean Valid;
XMLDocument XMLdoc = new XMLDocument();
Dialog dialog = new Dialog("Enter File Name Complete Path");
DialogField xmlfile;
XMLNode rootNode, bodyNode,bodyNode1,AttNode;
XMLNodeList bodyLines,childLine;
XMLElement xmlElement;
XMLNodeList _xmlNodelist;
commaIO myfile;
;
xmlfile = dialog.addField(typeid(filenameopen),"XML File Name");
dialog.filenameLookupFileName("*.xml");
if (dialog.run())
{
if(xmlfile.value() == "")
throw warning (strfmt("@SYS26332","XML Name"));
else
{
filename = xmlfile.value();
Valid = true;
}
}
dialog.close();
if (Valid){
XMLdoc.load(filename);
if(!xmldoc.load(filename)){
box::info("Can't load xml document");
break;
}
txtFile = "C:\\Tmp\\XmlData.txt";
myfile = new commaIO(txtFile,"w");
rootNode = xmldoc.documentElement();
nodeName = rootnode.baseName();
xmlElement = xmldoc.documentElement();
if(rootnode.hasChildNodes()){
bodyLines = rootnode.childNodes();
for(j = 0; j< bodyLines.length(); j++){
bodyNode = bodyLines.nextNode();
strTxtRow = bodyNode.baseName();
myfile.write(strTxtRow);
if(bodyNode.hasChildNodes()){
childLine = bodyNode.childNodes();
for(k= 0; k<childLine.length(); k++){
strTxtRow = "";
bodyNode1 = childLine.item(k);
nodeName = bodyNode1.baseName();
AttNode = xmlElement.getAttributeNode(nodeName);
strTxtRow = nodeName;
_xmlNodelist = bodyNode.selectNodes(nodeName);
for(i= 0;i< _xmlNodelist.length();i++){
strTxtRow = strTxtRow + ': ' +
_xmlNodelist.item(i).text();
}
//strTxtRow = strTxtRow + ': ' +
bodyNode.selectSingleNode(nodeName).text();
myfile.write(strTxtRow);
}
}
// nodeName = bodyNode.baseName();
// box::info(nodeName);
}
}
box::info("Records are Imported to XmlData.txt File at
C\\Tmp\\:","Import Operation","XML to Axapta");
}
}
--
Mallik Gudidevuni
"Lennart Conrad" wrote:
> Hi Mallikarjun
> The XMLDataImport class can be used to import data into tables. If you have
> exported using XMLDataExport class, you should be able to import using the
> XMLDataImport class. The import is using the SAX framework (Simple API for
> XML).
>
> If you can't get this to work yourself, place a reply and I will make a
> simple code example.
>
> Regards
> Lennart
>
>
> "Mallikarjun Gudidevuni" wrote:
>
> > Hi JF,
> > Thanks for u r help, I will look at the class. if passible can u send
> > the sample code to read a file and store it in to table.
> > --
> > Mallik Gudidevuni
> >
> >
> > "Mallikarjun Gudidevuni" wrote:
> >
> > > Hi All,
> > > How can I read data from a XML file to Axapta table. Can any one give the
> > > code to read from a XML file and write to Axapta Table or can any one suggest
> > > what classes to be used to read the data from XML file.
> > >
> > > I will be very thanking, if any one help in this regard.
> > >
> > > With Regards
> > > Mallikarjun Gudidevuni
> > >
> > >
> > > --
> > > Mallik Gudidevuni