Skip first line when parsing an xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kemal

    Skip first line when parsing an xml file

    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

    #2
    Re: Skip first line when parsing an xml file

    On 16 Dec 2003 16:39:22 -0800, u0ke@dcs.shef.a c.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)

    Comment

    • Pedro Graca

      #3
      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.=$lin e;
      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 =--

      Comment

      • Kemal

        #4
        Re: Skip first line when parsing an xml file

        Pedro Graca <hexkid@hotpop. com> wrote in message news:<broa51$5k 9f6$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.=$lin e;
        > 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!

        Comment

        • FLEB

          #5
          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$5k 9f6$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.=$lin e;
          >> 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.ev il.ones.will.bo w-down-to.us
          (put "Hey!" in the Subject line for priority processing!)
          -- http://www.pixelsaredead.com

          Comment

          Working...