Cross-Platform Web Services Using C# & JAVA (Charles River Media Internet & Web Design)

Self-Describing XML

Consider the following data.

Cross Platform Web Services Using C# and Java, Brian Hochgurtel, 500, 2003

Before the advent of XML, transmitted data often looked like the previous data. A programmer would rely on another individual to state which field represented which data. The elements used in XML documents should describe the data they represent. When we covert the simple text data shown previously into XML, the results may look like the following.

<?XML VERSION="1.0"?> <BOOK> <TITLE>Cross Platform Web Services</TITLE> <AUTHOR>Brian Hochgurtel</AUTHOR> <PAGECOUNT>500</PAGECOUNT> <YEARPUBLISHED>2003</YEARPUBLISHED> </BOOK>

In this example, the elements, such as <TITLE></TITLE>, describe the data represented. The XML standard allows a programmer to choose any element name needed to describe the data, but if the names chosen aren’t descriptive, the following could be the result.

<?XML VERSION="1.0"?> <THING> <NAME>Cross Platform Web Services</NAME> <PERSON>Brian Hochgurtel</PERSON> <NUMBER>500</NUMBER> <YEAR>2003</YEAR> </THING>

You no longer know that the data represents a book. Instead, it represents some sort of thing but you are no longer sure what type of thing it represents. In the previous example, you knew that the data represented information for a particular book.

You will see that SOAP messages are not really self-describing. Remember that these messages are meant for applications to read, so the message formats are not as clean as some of the other XML languages such as the eXtensible Stylesheet Language (XSL).

Категории