![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: XML question [Thread Next] Re: XML questionTo: NULL Date: 2/2/2007 8:07:00 PM
jencinas69@g... wrote:
> The text file is tab delimited
There are lots of ways then to build the XML but as you do not seem to
intend to tell us what format you want here is a PHP code snippet that
parses the tab delimited text and streams XML to the browser:
$lines = file('file.txt');
header('Content-Type: application/xml');
$xmlWriter = new XmlWriter();
$xmlWriter->openURI('php://output');
$xmlWriter->setIndent(True);
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startElement('root');
foreach ($lines as $line) {
$xmlWriter->startElement('row');
foreach (explode("\t", rtrim($line)) as $item) {
$xmlWriter->writeElement('col', $item);
}
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endDocument();
XML looks like this
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<col>Kibo</col>
<col>Xibo</col>
</row>
<row>
<col>Maho</col>
<col>Jaffo</col>
</row>
<row>
<col>1.5</col>
<col>3.14</col>
</row>
</root>
when this text
Kibo Xibo
Maho Jaffo
1.5 3.14
is parsed.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
