SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: XML parsing

  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML parsing

    Hi all
    I want to parse an XML file which does not have a root node. I am using SAX parsing. Is there anyway in PHP to add a root node?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,250
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    root node

    Hi c_mike, welcome to the forums,
    You have an XML file with no root nodes? Do you mean instead of something like this
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <therootnode>
      <itemnode>
         <anothernode>
            <anemptynode/>
            <atextnode>Hello, world!</atextnode>
          <anothernode>
       </itemnode>
       <itemnode>
         <anothernode>
            <anemptynode/>
            <atextnode>Hello, world!</atextnode>
          <anothernode>
       </itemnode>
    </therootnode>
    you have something like this
    Code:
      <itemnode>
         <anothernode>
            <anemptynode/>
            <atextnode>Hello, world!</atextnode>
          <anothernode>
       </itemnode>
       <itemnode>
         <anothernode>
            <anemptynode/>
            <atextnode>Hello, world!</atextnode>
          <anothernode>
       </itemnode>
    If the file won't parse you could use PHP's file functions to write the beginning and end nodes to the XML file and then parse it.

  3. #3
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Thanks very much. Like to have your valuable tip on file functions as well. I can easily append the end tag by opening the file in append mode and writing. But I wonder how I can add a string at the beginning. Is it that I have to do some file copying? When I am inserting the start tag by keeping the file pointer at the beginning, it overwrites the charactes that already exists in the file.
    Thanks again
    Mike


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •