简体   繁体   中英

Populate a Custom XML Structure From a MySQL Table Row-By-Bow

I have this custom tag structure:

<warehouse>

    <frontbay>

    </frontbay>

    <bayrow>

        <bay>

        </bay>

        <bay>

        </bay>

        <bay>

        </bay>

        <bay>

        </bay>

        <bay>

        </bay>

        <bay>

        </bay>

     </bayrow>  

     <aisle>

     </aisle>       

     <bayrow>

           ...more bays...

     </bayrow>

     <aisle>

     </aisle>

    </warehouse>

What is the best way to make the <bay> s inside the <bayrow> s in to a list, starting from the first one and catching all to the last one, to pass data from a MySQL database?

  • The bay, and its corresponding row on the MySQL table, will always stay the same.
  • Essentially it should be directly linked to my primary, auto-incrementing Bay. So bay 1 in the elements is the first row of the 'BayNumber' column.
  • If, at a later date, I wanted to make BayNumber:1 start at a different element - not necessarily the first one in the structure, which method would be best of the following?

With consideration to the above as well as for the purpose of speed, would it be best to:

  1. Give each bay its own ID ?

  2. Write code pointing to its place on the MySQL table directly inside each bay?

  3. Write a script to compile a list of the bays, and pass the table rows in one by one to each element in the list?

    • And if a script, would you recommend using JS or PHP to get the list? (I'm new to PHP, but I know some Javascript & jQuery)

I could be completely missing a better method to do this, such as placing a reference to the elements in to the MySQL table or something like that, so please advise me on the best course of action for Populating a Custom XML Structure From a MySQL Table Row-By-Bow .

You may be overthinking this problem. Generating an XML file with 2500 tags shouldn't take that long, unless their contents are really large.

I would try with the naive approach fist: generate the whole file on each request and keep an eye on the server load. Maybe cache the result and purge the cache when the database changes.

But if you really want to take this route, I would definitely add an id attribute to each <bay> tag, matching the primary key of your bay entity in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM