?
Solved

XML Design

Posted on 2014-07-26
5
Medium Priority
?
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 300 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

762 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