XML Faqs
XML Faqs
XML Faqs
1. What Is XML?
Because XML is a meta-markup language, it lets you create your own markup
language.
o HTML uses predefined tags, whereas XML uses user-defined tags which
can be used to identify data relationships like hierarchical
structure(elements, subelements, subsubelements,and so on.)
o HTML specifies its representation, whereas XML identifies the content for
the data.
o Unlike HTML, XML tags are well-formed. XML data is searchable,
format-free and reusable.
11. What is XML attribute?
Empty tag is a tag with ending "/>" and used to mark something in your well-
formed tags. It doesn't contain any content, so it is called "empty tag". It has two
forms:
<info/>
Note: not </info>
or
<tg> </tg>
or
<Greeting text="hello guys" />
Comments are ignored by XML parsers. A program will never see them in fact,
unless you activate special settings in the parser. XML comments are very much
like HTML comments.
It is worth noting that Comments must not come before an XML declaration or
inside markups. You cannot use "--" between your comments. You can use
comments to hide or remove parts of documents as long as the enclosed parts do
not themselves contain any comments.
15. How to deal with special characters in XML like < or &, etc.?
Like HTML, you should use entity reference to replace them, even if in
embeded JavaScript code.
Prologs come at the very beginning of XML documents. Like HTML's tag
<html>, XML prolog is a declaration that is used to indicate the start of XML
file like the following:
<?xml version="1.0"?>
or
<?xml version='1.0' encoding='utf-8'?>
or
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
It contains some or all of three attributes:
It is a good practice to include XML prolog whenever you create an XML file,
though it is optional.
Return to top
<?target instructions?>
where <? is the start and ?> is the end of procession instruction, the "target" is the
name of the application that is expected to do the processing, and "instructions" is
a string of characters that embodies the information or commands for the
application to process. Note: there cannot be any space between the initial <? and
the target identifier. The "instructions" begins after the first space. Fully
qualifying the target with the complete web-unique package prefix is
recommended. For readability, use a (:) after the target name. Like
<?my.subdirectory.myprograme: query="..."?>
Yes. XML tags are case-sensitive. The start and end tags should be matched
exactly.
o Use a style sheet to indicate to a browser how you want the content of the
elements to be displayed, like Cascading Style Sheet(CSS) or Extensible
Style Sheet Language(XSL).
o use a programming language to handle the XML document in
programming code,like Java or JavaScript.
22. Which is better to store data using elements or using attributes?
Return to top
<html>
<head>
<xml id="Myxml" src="hello.xml"></xml>
<script language="JavaScript">
function getData(){
xmldoc=document.all("Myxml").XMLDocument;
node=xmldoc.documentElement;
nodeMsg=node.firstChild;
output="From hello.xml file, you get -- " +
nodeMsg.firstChild.nodeValue;
message.innerHTML=output;
}
</script>
</head>
<body>
<h1 align=center>Get data from XML document</h1>
Here comes: <div id ="message"></div>
<input type="button" value="get data from xml"
onclick="getData()">
</body>
</html>
Here is the display in your browser. Click the button to see what happens? Click
the "F5" button on your keyboard to refresh the display.
A DTD tag is a tag used in DTD definition file. It starts with <! and ends with >.
It tells parser how to handle xml file.
26. What is the basic syntax for the document type declaration?
This is a DTD tag definition. The notation says that a slideshow element consists
of one or more slide elements. If there is no plus sign after slide, it says that a
slideshow has only one slide element. If the plus sign is replaced with question
mark "?", it says there may be zero or one slide. If the plus sign is replaced with
asterisk "*", it say that there may be zero or more slide elements.
The first line says that a slideshow element contains one or more slide elements.
The second line says that a slide element consists of a title followed by zero or
more item elements. The third line says that a title element consists entirely of
parsed character data(PCDATA). The "#" sign that precedes PCDATA indicates
that what follows is a special word. The fourth line says the item element is
either PCDATA or an item. The asterisk at the end says that either one can occur
zero or more times in succession. The fifth line says that content is a parameter
entity reference.
The content of a tag in the xml file can be #PCDATA or any number of item
elements like the fourth line above.
No. The DTD definition is not hierarchical. But you can work around to make
your xml tags hierarchical. For example, if you have a title for slideshow and a
title for each slide, you can use slide-title to represent the title in slide and make
a definition for slide-title. It is so called "hyphenation hierarchy. Otherwise, the
title definition will work for every title in xml file.
There are two special values: ANY or EMPTY. The "ANY" notation says that
the element may contain any other defined element, or PCDATA. The "EMPTY"
notation says that the element contains no contents. For example an empty tag
contains no contents.
If the DTD definition is in a separate file from the XML document, you have to
write something to reference it from the XML document. For example, if your
slideshow.dtd is ready for use, then, in your xml document file, after the xml
declaration, write:
The above statement says that the element slideshow tag will use definition in
slideshow.dtd. The SYSTEM identifier specifies the location of the DTD file and
the path is relative to the location of the xml document. You may use http:// or
file:/ to indicate the path of the DTD file.
Or you can reference a definition within the XML document by using a square
brackets like the following, rather than referring to an external DTD file.
53. What is the meaning of ATTLIST? What do the following statements tell us?
ATTLIST means attribute list. The name that follows ATTLIST specifies the
element for which the attributes are being defined. For example, you have a
slideshow tag with title, date and author attributes, you may code as:
The DTD tag ATTLIST begins the series of attribute definitions. The slideshow
element has three attributes. The title, date and author are the names of attributes
of slideshow. CDATA is a type of the attribute; it means unparsed charater data or
a text string.
The #REQUIRED means the attribute value must be specified in the document.
The #IMPLIED means the value need not be specified in the document.
The & sign means an entity variable name. Note it should be ended with
semicolon ";" sign. For example:
...
©right; ...
Wherever the ©right; is parsed, it will be replaced with entity copyright sign
©.
Use <!ENTITY> to declare it and use an % as start and ; as end to enclose the
parameter entity reference. For example, TODAY is a parameter entity
reference.
<!DOCTYPE DOCUMENT [
<!ELEMENT GREETING (#PCDATA)>
<!ELEMENT MESSAGE (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ENTITY TODAY "NOV 1, 2003">
]>
<DOCUMENT>
<GREETING>
HELLO FROM HTML
</GREETING>
<MESSAGE>
WELCOME TO THE WILD WORLD
</MESSAGE>
<DATE> &TODAY; </DATE>
</DOCUMENT>
Save above file as greeting.xml, use your browser to look at it. You may get a
similar display, except that the <DATE> tag will display "NOV 1, 2003".
Note: It is possible that your browser may not support XML. If you use MS IE
5.5 above, or NS 5.0 above, you may be able to see it.
Conditional section is a way to let XML document to choose which dtd should
be "included" or "ignored". Use <![ as a start and ]]> as an end. For example,
you want to use a different versions of a DTD for xml document or sgml
document, you may code as follows:
<![ INCLUDE [
... XML-only definitions
]]>
<![ IGNORE [
... SGML-only definitions
]]>
... common definitions
Return to top
The xmlns stands for XML NameSpace. It is an attribute fro a tag. It is used in
DTD to prevent conflicts. For example, the following tells us the title element
will use designated DTD.
xsi:noNamespaceSchemaLocation='YourSchemaDefinition.xsd'
The line specifies the schema to use for elements in the document that do not
have a namespace prefix.
o SAX -- Simple API for XML: reads and writes XML data in a server.
o DOM -- Document Object Model: converts an XML document into a
collection of objects.
o JDOM -- Java DOM: processes more data-oriented structures.
o dom4j -- DOM for Java: a factory-based implementation, easier to modify
for complex, special-purpose apps.
o DTD -- Document Type Definition: specifies the kinds of tags that can be
included in XML document.
o Namespace -- writes an XML document that uses two or more sets of
XML tags in modular fashion.
o XSL -- Extensible Stylesheet Language: specifies how to identify data, not
how to display it.
o XSLT -- Extensible Stylesheet Language for Transformations: specifies
what to convert an XML tag into.
o XSL-FO -- Extensible Stylesheet Language for Formatting Objects:
specifies how to link multiple areas on a page.
o SAAJ -- SOAP with Attachments API for Java.
o JAXR -- Java API for XML Registries, used to look and find web services.
o etc.
63. What are major subcomponents of XSL?
The transformation language lets you transform documents into different forms,
while the formatting language actually formats and styles documents in various
ways.
3. What is JAX-RPC?
JAX-RPC stands for Java API for XML-based RPC. It is an API for building
Web services and clients that use RPC and XML.
A value type is a class whose state may be passed between a client and remote
service as a method parameter or return value. For example, an account class
may have account number, account owner and amount field. These information
may be passed between client and server as a method deposit parameter and a
return value of method account query.
Return to top
SAAJ stands for SOAP(Simple Object Access Protocal) with Attachments API
for Java. SAAJ is used mainly for the SOAP messaging that goes on behind the
scenes in JAX-RPC and JAXR implementations.
Secondarily, it is an API that developers can use when they choose to write
SOAP messaging applications directly rather than using JAX-RPC.
JAXR stands for Java API for XML Registries. It enables Java software
programmers to use an API to access a variety of XML registries. The current
version of the JAXR specification can be found at
http://java.sun.com/xml/downloads/jaxr.html
XHTML is an application of XML that tries to make XML documents look and
act like HTML documents. The XHTML specification is a reformulation of
HTML 4.0 into XML. The following is code of XHTML.
1. <?xml version="1.0"?>
2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4. <html xmlns="http://www.w3.org/2002/xhtml" xml:lang="en"
lang="en">
5. <head><title>Welcome to see xhtml</title></head>
6. <body>
7. <h1 align="center"> Welcome to XHTML!</h1>
8. </body>
9. </html>
Name:
Customer ID:
Department:
Purchase Date:
Product:
<<<>>>
result.
Return to
top