Solved

XML Design

Posted on 2014-07-26
5
125 Views
Last Modified: 2014-08-13
Consider the following XML which is transmitted from Clients to a Server
<?xml version="1.0" encoding="UTF-8"?>
<td:MediaTerminal xmlns:td="http://www.tbd.com/messages">
  <td:MediaSource>
    <td:KeyWord>lena</td:KeyWord>
    <td:UDP>
      <td:Interface>225.10.10.2</td:Interface>
      <td:Port>1234</td:Port>
      <td:TTL>2</td:TTL>
    <td:UDP>
    <td:TCP>
      <td:Interface>225.10.10.2</td:Interface>
      <td:Port>1234</td:Port>
    <td:TCP>
    <td:File></td:File>
  </td:MediaSource>
  <td:MediaDestination Protocol="udp" Port="1234">
    <td:KeyWord></td:KeyWord>
    <td:Interface></td:Interface>
  </td:MediaDestination>
  <td:MediaDestination Protocol="udp" Port="1234">
    <td:KeyWord></td:KeyWord>
    <td:Interface></td:Interface>
  </td:MediaDestination>
</td:MediaTerminal>

Open in new window


The elements under MediaSource, are all optional.  Secondly, if a clients are only allowed to choose td:UDP, td:TCP or td:File for transmittal to the Server.  IOW:  I could do:

<?xml version="1.0" encoding="UTF-8"?>
<td:MediaTerminal xmlns:td="http://www.tbd.com/messages">
  <td:MediaSource>
    <td:KeyWord>lena</td:KeyWord>
    <td:TCP>
      <td:Interface>225.10.10.2</td:Interface>
      <td:Port>1234</td:Port>
    <td:TCP>
  </td:MediaSource>
   :
   :
</td:MediaTerminal>

Open in new window


or

<?xml version="1.0" encoding="UTF-8"?>
<td:MediaTerminal xmlns:td="http://www.tbd.com/messages">
  <td:MediaSource>
    <td:KeyWord>lena</td:KeyWord>
    <td:File></td:File>
  </td:MediaSource>
   :
   :
</td:MediaTerminal>

Open in new window


or

<?xml version="1.0" encoding="UTF-8"?>
<td:MediaTerminal xmlns:td="http://www.tbd.com/messages">
  <td:MediaSource>
    <td:KeyWord>lena</td:KeyWord>
    <td:UDP>
      <td:Interface>225.10.10.2</td:Interface>
      <td:Port>1234</td:Port>
      <td:TTL>2</td:TTL>
    <td:UDP>
  </td:MediaSource>
   :
   :
</td:MediaTerminal>

Open in new window


Two questions:  
1. How does an end user who'll design a client app for interfacing with my server know that the elements are optional?
2. How do they know td:UDP, td:TCP and td:File are mutually exclusive
3.  How does the approach above compare to the one below  (i.e. what's good practice)?  Think I've perused alot of documentation on XML design but would like a second/third opinion on approach used.

  <td:MediaSource>
    <td:KeyWord>lena</td:KeyWord>
    <td:UDP Interface="225.10.10.1" Port="1245">
      <td:TTL>2</td:TTL>
    <td:UDP>
    <td:TCP Interface="225.10.10.2" Port="33223">
    <td:TCP>
    <td:File>"Test"</td:File>
  </td:MediaSource>

Open in new window

0
Comment
Question by:forums_mp
  • 3
  • 2
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 100 total points
ID: 40223246
1. Tell them
2. Tell them
3. Uhmmm - 6 of one and half a dozen the other. In the latter you are sending unneeded data but in the realm of a few bytes it's unlikely to make much difference but since you can only have one or the other it's more likely confusing.
0
 

Author Comment

by:forums_mp
ID: 40223600
What would your recommendation on eliminating the confusion?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40224299
Only allow a single node for one or the other values - td:UDP, td:TCP or td:File
0
 

Author Comment

by:forums_mp
ID: 40229016
Not sure I'm following. Demonstrate with an example using the mediaSource element to show what you're proposing
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229091
You already have the samples in your opening question where you asked which was better
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now