[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

How to read a XML file and write to Axapta Table

Mallikarjun Gudidevuni

11/8/2005 7:40:00 AM

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
7 Answers

JF

11/8/2005 3:31:00 PM

0

Hi,

you may use the "XMLDocument" class to read in a XML document and then use
the "XMLNode" and "XMLNodeList" class to read the tags of the XML file into a
Axapta variable or table field.

Hope this helps as a starting point.

Cheers


"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

Mallikarjun Gudidevuni

11/9/2005 5:11:00 AM

0

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

Lennart Conrad

11/9/2005 10:31:00 AM

0

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

JF

11/9/2005 1:10:00 PM

0

Here a short example, job reads a xml file and stores in table.

static void Read_XML_File(Args _args)
{
TestCust TestCust; //table
XMLDocument doc;
XMLNode rootNode;
XMLNodeList CustHeaderNode;
XMLNode CustLineNode;
XMLParseError xmlError;
int i;

doc = new XMLDocument();
doc.async(FALSE);
doc.load("C:\\TestFile.xml");
xmlError = doc.parseError();

if (xmlError && xmlError.errorCode() != 0)
{
xmlError.reason();
return;
}

rootNode = doc.documentElement();

ttsbegin;

CustHeaderNode = rootNode.selectNodes('//Customer');

for (i=0; i<CustHeaderNode.length(); i++)
{
CustLineNode = CustHeaderNode.item(i);
TestCust.AccountNum =
custLineNode.selectSingleNode('AccountNum').text();
TestCust.Name =
custLineNode.selectSingleNode('Name').text();
TestCust.AccountGroup =
custLineNode.selectSingleNode('Gruppe').text();
TestCust.insert();
}

ttscommit;
}


regards



"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

Mallikarjun Gudidevuni

11/11/2005 10:36:00 AM

0

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

Mallikarjun Gudidevuni

11/11/2005 11:11:00 AM

0

Hi JF,
Thanks JF, Ur Code was very much use full to me.
--
Mallik Gudidevuni


"JF" wrote:

> Here a short example, job reads a xml file and stores in table.
>
> static void Read_XML_File(Args _args)
> {
> TestCust TestCust; //table
> XMLDocument doc;
> XMLNode rootNode;
> XMLNodeList CustHeaderNode;
> XMLNode CustLineNode;
> XMLParseError xmlError;
> int i;
>
> doc = new XMLDocument();
> doc.async(FALSE);
> doc.load("C:\\TestFile.xml");
> xmlError = doc.parseError();
>
> if (xmlError && xmlError.errorCode() != 0)
> {
> xmlError.reason();
> return;
> }
>
> rootNode = doc.documentElement();
>
> ttsbegin;
>
> CustHeaderNode = rootNode.selectNodes('//Customer');
>
> for (i=0; i<CustHeaderNode.length(); i++)
> {
> CustLineNode = CustHeaderNode.item(i);
> TestCust.AccountNum =
> custLineNode.selectSingleNode('AccountNum').text();
> TestCust.Name =
> custLineNode.selectSingleNode('Name').text();
> TestCust.AccountGroup =
> custLineNode.selectSingleNode('Gruppe').text();
> TestCust.insert();
> }
>
> ttscommit;
> }
>
>
> regards
>
>
>
> "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

go

11/3/2009 12:19:00 PM

0

well, it should be
select * from YOURTABLE a where col3 in (select top 1 b.col3 from
YOURTABLE b where a.col1 = b.col1)

sorry for the f**kup
///M

go skrev:
> In sql it should be something like (if col3 is id and you want first
> record of col1)
>
> select * from YOURTABLE a where col3 not in (select top 1 b.col3 from
> YOURTABLE b where a.col1 = b.col1 and a.col2 = b.col2)
>
> haven't tested it, but there's something to start with.
>
> ///M
>
> Patrice skrev:
>>
>> "Chris" <Chris@discussions.microsoft.com> a ?crit dans le message de
>> news:3D4E87A8-1488-48F3-9BA2-59C8F17C3326@microsoft.com...
>>> Imagine there is a DB table:
>>>
>>> col1 col2 col3
>>> ---------------------
>>> 1 A 10
>>> 1 B 11
>>> 1 C 12
>>> 2 D 13
>>> 2 E 14
>>> 2 F 15
>>>
>>> How to write both sql and linq queries (I DONT want to use a
>>> subquery) to
>>> get rows - min of col3 groupped by col1 BUT WITH col2:
>>>
>>> the result should be:
>>>
>>> col1 col2 col3
>>> ---------------------
>>> 1 A 10
>>> 2 D 13
>>>
>>
>> And col2 is also the min value ? For now it looks to me you group by
>> col1, with the MIN aggregate function for both col2 and col 3 (i. just
>> adding MIN(col2) to your query would be enough)...
>>
>> --
>> Patrice