S/w fAQ's
S.No   Category views Poted On
1 SQA and testing frequently asked definitions

TESTING

999 01/01/08
2 Load testing interview questions

TESTING

2547 01/01/08
3 Performance Testing Considerations

TESTING

525 01/01/08
4 what is testing?

TESTING

658 01/01/08
5 blackbox testing tips

TESTING

4254 01/01/08
6 Tester Tips

TESTING

6589 01/01/08
7 Interview with Brian Marick on How to do Good Test..

TESTING

254 01/01/08
8

WEB Testing Interview Questions For software teste...

TESTING

5846 02/02/08
9 General interview questions

TESTING

5554 02/02/08
10 Latest Questions in Testing Definations

TESTING

5885 02/02/08
11 Software Testing Interview Questions

TESTING

556 02/02/08
12 Interview Questions for Software Testers.

TESTING

658 02/02/08
13 Testing Interview Questions

TESTING

2135 02/02/08
14 Testing Tools Interview Questions

TESTING

245 02/02/08
15 TESTING TOOLS INTERVIEW QUESTIONS-Part2

TESTING

546 02/02/08
16 TESTING TOOLS INTERVIEW QUESTIONS-Part1

TESTING

879 02/02/08
17 Fuzz testing

TESTING

1245 02/02/08
18 Defect Tracking & Formal Verification

TESTING

471 02/02/08
19 Test Cases, Suits, Scripts

TESTING

501 02/02/08
20 Compatibility Testing

TESTING

2456 02/02/08
21 System Testing & Regression Testing

TESTING

4511 02/02/08
22 Beta Testing & Product Testing

TESTING

6548 02/02/08
23 Installation Testing & Alpha Testing

TESTING

235 02/02/08
24 Stability Testing & Acceptance Testing

TESTING

546 02/02/08
25 Usability Testing

TESTING

546 02/02/08
26 Stress Testing & Security Testing

TESTING

856 02/02/08
27 Performance Testing

TESTING

214 02/02/08
28 Unit Testing & Integration Testing

TESTING

568 02/02/08
29 White Box & Black Box Testing

TESTING

546 02/02/08
30 Interview questions on WinRunner TESTING 125 03/02/08
31 Testing Tools Interview Questions TESTING 658 03/02/08
32 Testing Tools Interview Questions-2 TESTING 5488 03/02/08
33 Testing Tools Interview Questions-3 TESTING 254 03/02/08
34 Testing Tools Interview Questions-4 TESTING 987 03/02/08
35 Testing Tools Interview Questions TESTING 2456 03/02/08
36 Testing Tools Interview Questions TESTING 2145 03/02/08
37 Software Testing 10 Rules-Bugs and fixes TESTING 985 03/02/08
38 How to Write a Fully Effective Bug Report TESTING 357 03/02/08
39 Testing Reviews--methodology and techniques TESTING 159 03/02/08
40 Load and Performance Test Tools TESTING 658 03/02/08
41 TESTING 856 03/02/08
42 Debugging Strategies, Tips, and Gotchas TESTING 2145 03/02/08
43 Web services programming tips and tricks: Stress t... TESTING 84754 03/02/08
44 Web services programming tips and tricks: improve ... TESTING 2358 03/02/08
45 WinRunner Interview Questions TESTING 3569 03/02/08
46 LoadRunner Interview Questions TESTING 1245 03/02/08
47 SilkTest Interview Question TESTING 845 03/02/08
48 Software QA and Testing Frequently-Asked-Questions... TESTING 21 03/02/08
49 Systematic Software Testing TESTING 254 03/02/08
50 Software Testing-Introduction TESTING 2586 03/02/08
51 Tips for Releasing Software for Customer Testing TESTING 358 03/02/08
52 Software Regression Testing TESTING 951 03/02/08
53 TestComplete 4 - Automate the Non-Automatable. TESTING 32558 03/02/08
54 webtest tools TESTING 245 03/02/08
55 webtest tools TESTING 956 03/02/08
56 Applying Patterns to Software Testing TESTING 845 03/02/08
57 The Software Testing Automation Framework TESTING 326 03/02/08
58 Testing Tools Interview Questions and Faqs-unanswe... TESTING 745 03/02/08
53 latest and unanswered Questions in Rational Robot ... TESTING 5125 03/02/08
54 Buttons TESTING 648 03/02/08
55 XPLANNER TESTING 213 03/02/08
56 Testing Tools Interview Questions TESTING 9547 03/02/08
57 Web services programming tips and tricks: TESTING 852 03/02/08
         

Web services programming tips and tricks:

Some programs depend on a distinction between a null array and an empty array. What is often used to represent arrays in XML schemas does not have any such distinction. Is there anything you can do to get around this feature of XML? This article will show you.

When working with Web services, it is all too often assumed that anything that can be done in a programming language can be done in XML. There are many cases where that is not true. This tip addresses one of those cases: the distinction between an array which is null, and an array which has no elements.

An XML array

Most programming languages, like the Java language, have the concept of an array: a sequential collection of like elements. XML also has a sequential collection of like elements: an XML schema element with a maxOccurs attribute whose value is greater than 1. So it stands to reason that the Java language's sequential collection of like elements would map nicely to XML's sequential collection of like elements. Listing 1 defines a complexType which contains such an XML schema 'array'.

Listing 1. A complexType containing an 'array'



nillable="true" type="xsd:int"/>



The problem

This XML "array" is not strictly an array. It is an element with an occurrence constraint, which means that the element is defined to occur a specific number of times, in this case 0 or more times. This does sound a lot like an array, and for most intents and purposes, it is. But the mapping isn't perfect. You should be aware of the shortcomings so they don't catch you by surprise.

Following the JAX-RPC mapping rules, the complexType in Listing 1 would become the Java bean in Listing 2 (actually, the bean would have getters and setters, but we'll keep it simple for this discussion).

Listing 2. A bean containing an array.
public class Bean {
public java.lang.String name;
public java.lang.Integer[] array;
}



(Note that Bean's array variable is an array of java.lang.Integer, not an array of int. The array element from the XML schema is nillable. A Java int cannot be null. A java.lang.Integer can be null. So we use java.lang.Integer in this mapping.)

number of examples of mapping an instance of the Java Bean to an instance of the corresponding XML. The first row is the Java representation; the second row is the corresponding XML representation.

One obvious thing to note about Table 1 -- and it's the topic of this tip -- is that an empty instance of a Java array and a null instance of a Java array map to the same XML instance. This is not good if you're depending on a distinction between the two.

One easy trap to fall into here is to guess that a null array inside a bean is really represented by the XML in the second column. But as we hope we've shown in the table, that really represents an array with a single element whose value is null, not a null array.

Is there a way around this issue?

Of course! The thing to be aware of is that an array in most programming languages is really made up of two things: there are the contents of the array and there is the array itself -- a wrapper, if you like, around the contents. An XML "array" is only a list of the elements. There is no wrapper.

So the solution is simple: create a wrapper for the array, as shown in Listing 3.

Listing 3. A bean containing a wrappered array.


"unbounded" minOccurs="0" type="xsd:int"/>










As you can see, the empty instance and the null instance of the arrayWrapper complexType are distinct from each other.

This solution isn't a cure-all. First of all, it's rather more complex than a simple minOccurs/maxOccurs representation of an array. Secondly, instead of a simple bean containing an array, this XML schema really looks like a bean containing a bean containing an array; and that's likely what you'll end up with if you map this XML schema into Java programming with your favorite JAX-RPC WSDL-to-Java tool. Until standards bodies recognize and map this wrapped array pattern appropriately, this solution is something you should apply only if you really must distinguish a null array from an empty array.



Summary

XML "arrays" are not truly arrays in a programming language sense. XML does not distinguish between a null array and an empty array. There is an XML schema pattern that you can follow to get the equivalent distinction, but this pattern is not well recognized by standards bodies and should only be used when absolutely necessary.