Tuesday, 4 December 2012

Writing and Reading to a XML File

Writing to a XML File

static void writeXML(Args _args)

{

XMLTextWriter xw; FileDemo ct;

;

xw = XMLTextWriter::newFile(“c:\\FileDemo.xml”);

xw.writeStartDocument();

xw.writeStartElement(“Details”);

while select ct

{

xw.writeStartElement(“CustomerDetails”);

xw.writeElementString(“Id”,ct.Id);

xw.writeElementString(“Name”,ct.Name);

xw.writeEndElement();

}

xw.writeEndElement();

xw.writeEndDocument();

xw.close();

}

Reading from a XML File

static void readingXML(Args _args)

{

XMLDocument xmlDoc = XMLDocument::newFile(“c:\\FileDemo.xml”);

int i, nooftags;

;

nooftags = xmlDoc.getElementsByTagName(“CustomerDetails”).length();

for(i=0; i<nooftags; i++)

{

info(strfmt(“%1″, xmlDoc.getElementsByTagName(“Id”).item(i).text()));

info(strfmt(“%1″, xmlDoc.getElementsByTagName(“Name”).item(i).text()));

}

}

No comments:

Post a Comment