user1455116
user1455116

Reputation: 2144

Specify the sequence in a XML file

I have the following xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<game>
  <a>
    <b>
      <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="picture">
        <pic>sample.png</pic>
      </test>
      <c>
        <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="content">
          <text> Something </text>
          <photo> p1.png </photo>
          <position> middle </position>
        </test>
        <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="content">
          <text> Something else </text>
          <photo> p2.png </photo>
          <position> corner </position>
        </test>
        <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="content">
          <text> some text here </text>
          <photo> p3.png </photo>
          <position> corner </position>
        </test>
      </c>
    </b>
  </a>
</game>

This xml is being parsed in a code which follow MVC architecture. The code is parsed by the model and presented on the view. The view should know the sequence behavior of the elements on the view. For example, in the above xml, when it is parsed and encounters the first tag in the tag, the view should have a picture samle.png on it. And when it comes below and sees the three tags which are inside the tag, the view should display the photo p1 initially and after a while, it should wipe out the photo p1 and then display photos p2 and p3 on the view.

We need not bother about the coding part here. The task is to tell to the code that 'this is the sequence' through the xml, which means that i need to write something in the xml that tells the sequence of the events above, which when parsed by the code, the code understands what is the sequence and renders it on the view accordingly.

Let me know if it is confusing, or let me know your approach here, i tried a couple of them but i dont think they are correct. Let me know if anyone can think of something

Upvotes: 0

Views: 219

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25054

The usual convention in XML applications is that the sequence of elements in an XML document may convey information, so all well designed general-purpose XML APIs make the sequence of children within a parent visible through the API. In a SAX interface, for example, the sequence of elements is conveyed by the sequence of SAX events. In a DOM interface, sequence information is recorded in properties on the nodes that allow you to find the next node in the sequence of children, etc.

So unless you are working with a singularly eccentric interface for your XML, you don't need to add sequencing information to the XML. You just need to make sure that your model has the sequencing information it needs, and that your code for populating the model from the XML does the right thing. Good luck.

Upvotes: 1

Related Questions