#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    6
    Rep Power
    0

    Dynamically saved XML file doesn't follow structure


    XML Newbie here - please be kind. I am using an XML file as a very small database, and my script can successfully read and manipulate the data. It can also add new entries, and save them to the file.

    The problem is, when the script saves the XML file, the new entries are all on one run-on line and do not follow the indentation/structure pattern of the file.

    In the following listing, I start with entries 0 and 1 already in the file, then I add entry 2, and the file becomes deformed:

    <main>
    <job id="0">
    <title>Job Title 1</title>
    <info>Job info 1</info>
    <contact>Contact info 1</contact>
    </job>
    <job id="1">
    <title>Job Title 2</title>
    <info>Job info 2</info>
    <contact>Contact info 2</contact>
    </job>
    <job id="3"><title>Job title 3</title><info>Job info 3</info><contact>contact info 3</contact></job></main>

    I am using XML DOM with ASP, although I doubt this is the problem or source of any concern at all (since it's just abstraction methods for reading/parsing the XML file, there is no control for such details).
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    2
    Rep Power
    0
    I had to do something similar and I used something like this:

    filename.WriteLine("<Diag>"+areyDiag+"</Diag>")
    filename.WriteLine("<Image>"+areyImage+"</Image>")

    and it worked fine. I'm new too so anyone with anything better should feel free to correct me...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Location
    Indianapolis, IN
    Posts
    3
    Rep Power
    0
    Any time I have done something similar with php, whether it is writing HTML or XML, I use the new line character "\n" and then if I want to use a tab then I use "\t".
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    6
    Rep Power
    0
    Well the thing is, this isn't like a normal file read/write operation. The XML DOM object abstracts that part, so all you do is like myxml.open(), myxml.appendnode(), myxml.save()

    That's why I can't seem to get any control over it - because it does everything for me.

    I was thinking about just making a simple flat-file database thing, but you know how pride starts messing with you and you think you can become an XML developer within a day?....

IMN logo majestic logo threadwatch logo seochat tools logo