Connecting Tech Pros Worldwide Forums | Help | Site Map

Skip first line when parsing an xml file

Kemal
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi, I have an xml file which I cant change, the problem is that the
first line looks like this <?xml version="1.0" ?> with the rest of
the xml being fine. However when I try to parse this I am getting a
malformed xml error. THis line was added recently, the parser worked
before. My question is how can I get rid of this first line in the
xml file - which I get from an internet feed using
fopen("http://dsfsf.com/sdf.xml", r);

Thanks

Kemal

Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Skip first line when parsing an xml file


On 16 Dec 2003 16:39:22 -0800, u0ke@dcs.shef.ac.uk (Kemal) wrote:
[color=blue]
>Hi, I have an xml file which I cant change, the problem is that the
>first line looks like this <?xml version="1.0" ?> with the rest of
>the xml being fine. However when I try to parse this I am getting a
>malformed xml error. THis line was added recently, the parser worked
>before. My question is how can I get rid of this first line in the
>xml file - which I get from an internet feed using
>fopen("http://dsfsf.com/sdf.xml", r);[/color]

What XML parser are you using? XML documents are supposed to start with that.

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Pedro Graca
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Skip first line when parsing an xml file


Kemal wrote:[color=blue]
> Hi, I have an xml file which I cant change, the problem is that the
> first line looks like this <?xml version="1.0" ?> with the rest of
> the xml being fine. However when I try to parse this I am getting a
> malformed xml error. THis line was added recently, the parser worked
> before. My question is how can I get rid of this first line in the
> xml file - which I get from an internet feed using
> fopen("http://dsfsf.com/sdf.xml", r);
>
> Thanks
>
> Kemal[/color]

If you are sure, *REALLY* sure, you want to do that,
try

<?php
$fh = fopen('whatever', 'r');
$dummy = fgets($fh);
$contents = '';
while ($line = fgets($fh)) $contents.=$line;
fclose($fh);
// parse $contents now
?>


*BUT* that is the proper way to start a XML file.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Kemal
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Skip first line when parsing an xml file


Pedro Graca <hexkid@hotpop.com> wrote in message news:<broa51$5k9f6$1@ID-203069.news.uni-berlin.de>...[color=blue]
> Kemal wrote:[color=green]
> > Hi, I have an xml file which I cant change, the problem is that the
> > first line looks like this <?xml version="1.0" ?> with the rest of
> > the xml being fine. However when I try to parse this I am getting a
> > malformed xml error. THis line was added recently, the parser worked
> > before. My question is how can I get rid of this first line in the
> > xml file - which I get from an internet feed using
> > fopen("http://dsfsf.com/sdf.xml", r);
> >
> > Thanks
> >
> > Kemal[/color]
>
> If you are sure, *REALLY* sure, you want to do that,
> try
>
> <?php
> $fh = fopen('whatever', 'r');
> $dummy = fgets($fh);
> $contents = '';
> while ($line = fgets($fh)) $contents.=$line;
> fclose($fh);
> // parse $contents now
> ?>
>
>
> *BUT* that is the proper way to start a XML file.[/color]


OK its started to work again now on its own. This is really bizzare!
I thought it was the correct way to start the file but the parser was
complaining about an error in the xml on line 1, so I assumed it was
that. Its still there but its working now. I dont get it!
FLEB
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Skip first line when parsing an xml file


Regarding this well-known quote, often attributed to Kemal's famous "17 Dec
2003 02:23:47 -0800" speech:
[color=blue]
> Pedro Graca <hexkid@hotpop.com> wrote in message news:<broa51$5k9f6$1@ID-203069.news.uni-berlin.de>...[color=green]
>> Kemal wrote:[color=darkred]
>>> Hi, I have an xml file which I cant change, the problem is that the
>>> first line looks like this <?xml version="1.0" ?> with the rest of
>>> the xml being fine. However when I try to parse this I am getting a
>>> malformed xml error. THis line was added recently, the parser worked
>>> before. My question is how can I get rid of this first line in the
>>> xml file - which I get from an internet feed using
>>> fopen("http://dsfsf.com/sdf.xml", r);
>>>
>>> Thanks
>>>
>>> Kemal[/color]
>>
>> If you are sure, *REALLY* sure, you want to do that,
>> try
>>
>> <?php
>> $fh = fopen('whatever', 'r');
>> $dummy = fgets($fh);
>> $contents = '';
>> while ($line = fgets($fh)) $contents.=$line;
>> fclose($fh);
>> // parse $contents now
>> ?>
>>
>>
>> *BUT* that is the proper way to start a XML file.[/color]
>
>
> OK its started to work again now on its own. This is really bizzare!
> I thought it was the correct way to start the file but the parser was
> complaining about an error in the xml on line 1, so I assumed it was
> that. Its still there but its working now. I dont get it![/color]

Hmm... makes me wonder if it was something like an ASCII/Binary mixup, or
some kind of CR/LF issue. Although it would choke on every line, it would
bomb first on Line 1.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Closed Thread