Question: How should XML data be stored in the database.

Source: Internet
Author: User

XMLHow should data be stored in the database.

 

Example,For example, a forum post, itsXMLThe document structure is as follows:

<? XML version = "1.0" eocoding = "gb2312"?>

 

<Post>

<Question post>

<PostId> 000001 </PostId>

<AuthorId>Xx</AuthorId>

posting time XX time posting time >

post topic > XX Problems post topic >

<Post content>XX content</Post content>

</Question post>

<Reply to post>

<Question postId> 000001 </Question postId>

<PostId> 0001 </PostId>

<AuthorId>Xx</AuthorId>

posting time XX time posting time >

<Post content>XX content</Post content>

</Reply to post>

<Reply to post>

<Question postId> 000001 </Question postId>

<PostId> 0002 </PostId>

<AuthorId>Xx</AuthorId>

posting time XX time posting time >

<Post content>XX content</Post content>

</Reply to post>

...

</Post>

 

So I have two design schemes (I think the second one is more feasible)

 

Solution 1:

Set the entireXMLA document is stored in a data table as a record.

The data table structure:Fileid(Document ID ),File(Document Content), Createdate(Creation Time)

Advantages of this solution: Simple Structure

Disadvantage: you cannot perform complex queries, such as searching all posts of an author.

 

Solution 2:

design two data tables, one for question posts and one for reply posts, use a foreignkey contact two tables, the two tables do not store all XML content, instead, XML each leaf node is designed as a field

TopicTable Data Structure:Topicid(Primary Key ),Userid,Createdate,Issue,Content

Reply Table Data Structure: Replyid (Primary Key ), Topicid (Foreign key, Topic Of Topicid Form a many-to-one relationship ), Userid , Createdate , Content

Advantages of this solution: Clear Data Classification for complex search

Disadvantage: Complicated Structure

 

At first glance, I think the second design scheme is more reasonable, but I immediately came up with a question:XMLThe file structure is relatively simple. It is easy to design leaf nodes into two-dimensional data tables. However, in reality, more complex data structures and attributes may appear, as shown below:

<A>

 <B>

<C att01 = "..." Att02 = "…">

<D>... </D>

</C>

...

 </B>

 ....

</A>

 

When such a relatively complex or even more complex structure occurs, it seems that the first solution is more common. However, the second solution is basically impossible (unless multiple data tables are created to form a complex association), data needs to be re-exported from multiple data tablesXMLIt must be quite complicated ,.

 

I just got started XML , learn more about XML advantages, but consider the specific XML with database applications, there is really no design experience. Please give me some advice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.