XML

  Home  Computer Programming  XML


“Learn XML programming and basic concepts with hundreds of XML Interview Questions and Answers and examples.”



27 XML Questions And Answers

21⟩ Do I have to know HTML or SGML before I learn XML?

No, although it's useful because a lot of XML terminology and practice derives from two decades' experience of SGML.

Be aware that ?knowing HTML? is not the same as ?understanding SGML?. Although HTML was written as an SGML application, browsers ignore most of it (which is why so many useful things don't work), so just because something is done a certain way in HTML browsers does not mean it's correct, least of all in XML.

 157 views

22⟩ Does XML replace HTML?

No. XML itself does not replace HTML. Instead, it provides an alternative which allows you to define your own set of markup elements. HTML is expected to remain in common use for some time to come, and the current version of HTML is in XML syntax. XML is designed to make the writing of DTDs much simpler than with full SGML. (See the question on DTDs for what one is and why you might want one.)

 186 views

23⟩ What does an XML document actually look like (inside)?

The basic structure of XML is similar to other applications of SGML, including HTML. The basic components can be seen in the following examples. An XML document starts with a Prolog:

1. The XML Declaration

which specifies that this is an XML document;

2. Optionally a Document Type Declaration

which identifies the type of document and says where the Document Type Description (DTD) is stored;

The Prolog is followed by the document instance:

1. A root element, which is the outermost (top level) element (start-tag plus end-tag) which encloses everything else: in the examples below the root elements are conversation and titlepage;

2. A structured mix of descriptive or prescriptive elements enclosing the character data content (text), and optionally any attributes (?name=value? pairs) inside some start-tags.

XML documents can be very simple, with straightforward nested markup of your own design:

 191 views

24⟩ How does XML handle white-space in my documents?

All white-space, including linebreaks, TAB characters, and normal spaces, even between ?structural? elements where no text can ever appear, is passed by the parser unchanged to the application (browser, formatter, viewer, converter, etc), identifying the context in which the white-space was found (element content, data content, or mixed content, if this information is available to the parser, eg from a DTD or Schema). This means it is the application's responsibility to decide what to do with such space, not the parser's:

► insignificant white-space between structural elements (space which occurs where only element content is allowed, ie between other elements, where text data never occurs) will get passed to the application (in SGML this white-space gets suppressed, which is why you can put all that extra space in HTML documents and not worry about it)

► significant white-space (space which occurs within elements which can contain text and markup mixed together, usually mixed content or PCDATA) will still get passed to the application exactly as under SGML. It is the application's responsibility to handle it correctly.

The parser must inform the application that white-space has occurred in element content, if it can detect it. (Users of SGML will recognize that this information is not in the ESIS, but it is in the Grove.)

 192 views

25⟩ Which parts of an XML document are case-sensitive?

All of it, both markup and text. This is significantly different from HTML and most other SGML applications. It was done to allow markup in non-Latin-alphabet languages, and to obviate problems with case-folding in writing systems which are caseless.

► Element type names are case-sensitive: you must follow whatever combination of upper- or lower-case you use to define them (either by first usage or in a DTD or Schema). So you can't say <BODY>?</body>: upper- and lower-case must match; thus <Img/>, <IMG/>, and <img/> are three different element types;

► For well-formed XML documents with no DTD, the first occurrence of an element type name defines the casing;

► Attribute names are also case-sensitive, for example the two width attributes in <PIC width="7in"/> and <PIC WIDTH="6in"/> (if they occurred in the same file) are separate attributes, because of the different case of width and WIDTH;

► Attribute values are also case-sensitive. CDATA values (eg Url="MyFile.SGML") always have been, but NAME types (ID and IDREF attributes, and token list attributes) are now case-sensitive as well;

► All general and parameter entity names (eg Á), and your data content (text), are case-sensitive as always.

 190 views