2004.11_Xml in Kde with Kxml Editor.pdf
(
7389 KB
)
Pobierz
Layout 1
LINUX USER
KTools
XML on KDE
Since it was first introduced, Extensible Markup Language (XML) has been
acclaimed as a revolution in the IT landscape. Visionaries even predicted the
end of HTML and conventional web design. Some of the hype has subsided, but
XML is stronger than ever. XML is not only for web design; it is also an impor-
tant format for sharing data between applications. This article shows how to
create and edit XML files using KDE’s KXML Editor.
BY STEPHAN LAMPRECHT
(kxmleditor), which is included in the
KDE tool set.
tools, and as the name suggests, it is
designed for the KDE desktop environ-
ment.
KXML offers many useful options but
the following features receive special
notice on the KXML home page:
•drag and drop editing and clipboard
support;
• DOM Level 2 Qt library parser;
•KParts technology support;
• DCOP technology support. support;
• support for editing KOffice compressed
files.
If your distribution does not include
KXML Editor, the current version is avail-
able at [4].
format for exchanging data.
Linux users access XML files
every day to complete their daily work.
OpenOffice, for instance, uses XML to
store information. KDE help also uses
XML. Even a program like TuxCards [2],
the Linux cue card application, uses the
XML file format. And XML is also used
as an extensible markup language for
web design. Despite XML’s affinity for
automation, you may occasionally have
to take the old-fashioned approach of
editing an XML file line by line with a
text-based editor. Of course, you can
always fire up vi, but an editor designed
especially for XML offers many advan-
tages over an ordinary text editor. This
article examines the KXML Editor tool
Do You Speak XML?
This article does not offer enough room
for a full discussion of the XML format,
so I’ll assume you have some familiarity
with XML. (In case you’re interested,
you’ll find more on XML at [3].) The
important thing to remember is that an
XML file is hierarchical, and an editing
tool that represents the relationships
among the elements in the file helps the
user manage the complexity of this
structured data.
To create or edit an XML file, all you
really need is a simple editor, however, it
is extremely difficult to read large, nested
documents using an ordinary text editing
tool. It makes far more sense to use spe-
cial tools. KXML Editor is one of these
Creating the Basic Structure
When first launched, KXML Editor
comes up with a well-organized work-
space (Figure 1). The first thing you need
to do is select
File /
Ve rsion&Encoding
to
define the basic char-
acteristics of the file.
Specify the XML ver-
sion and character set
in the dialog that then
appears.
The next step is to
start adding XML ele-
ments to the XML file.
You can select:
Insert / Element
to add an element. In
the dialog box that
appears (Figure 2),
KTools
In this column we present tools, month by
month, which have proven to be especially
useful when working under KDE, solve a
problem which otherwise is deliberately
ignored, or are just some of the nicer things
in life, which – once discovered – you would
not want to do without.
Figure 1: The KXML workspace. Your view of the workspace may vary
depending on which version of KXML Editor you are using.
76
November 2004
www.linux-magazine.com
Creating XML files with KDE’s KXML Editor
X
ML [1] is a simple and powerful
KTools
LINUX USER
ating multiple elements at the
same level in your structure,
you can copy the elements. To
copy an element, click the ele-
ment with your mouse, press
[Ctrl-C] to copy the element to
the clipboard, and then [Ctrl-
V] to insert the element at the
new location where you
would like to place the copy.
If an element called
<pho-
nenumber>
has an attribute
called
type
, you can define the attribute
by first selecting an element, then choos-
ing
Insert / Attribute
in the menu to open
the input windows. Type a name for the
attribute in the
Qualified Name
line, and then add a
Value>
(Figure 3).
Yo u n o w have an empty struc-
ture but not a document. To
create a document, you need to
add content to the elements you
have defined. To do so, select an
element and then select
Insert /
Te x t
or
Insert / CData
in the
menu. The elements in a XML
file are all parsed, with the exception of
elements tagged as
CData
.
Figure 2: The Insert Element dialog box.
Well-Formed Documents
The KXML Editor makes it easy to create
so-called well-formed XML documents
by making sure you keep to the XML lan-
guage rules. There is no need to pay
attention to the positioning of individual
characters. This said, the software has
no way of ensuring that a document will
be recognized as valid by an XML parser.
The parser needs the Document Type
Definition (DTD) to be able to do this.
Check out [3] for a HOWTO and help on
creating definition files.
you could then type
addresses
for
Local
Name
, for example. Click on
OK
to add
the element to the file.
To add a sub-element to an existing
element, first select the element in the
tree view on the left side of the screen.
Then either right click the element to
drop down the context menu and select
Element
, or use the
Insert / Element
menu item. Both approaches open the
same dialog. You can then assign a
Local
Name
to the element and specify its posi-
tion in the tree.
You can repeat this procedure to build
up a document structure. If you are cre-
■
Figure 3: Each element can have attributes. The attributes
are defined in this dialog.
Want to know what’s up next?
Subscribe
Subscribe
to Linux Magazine Preview,
our free monthly email newsletter!
WWW.LINUX-MAGAZINE.COM/NEWSLETTER
Want to know what’s up next?
Plik z chomika:
Kapy97
Inne pliki z tego folderu:
2007.09_Health Check-Tools for Checking System Status.pdf
(646 KB)
2004.12_Hunters and Gatherers-Reading the News with Akregator.pdf
(4910 KB)
2004.11_Xml in Kde with Kxml Editor.pdf
(7389 KB)
2004.10_Kickpim-a Panel Applet for Quick Access to Your Address Book.pdf
(1903 KB)
2004.09_Context Menus-Using the Right Mouse Button to Greater Effect.pdf
(2362 KB)
Inne foldery tego chomika:
Beginners
Business News
Comment
Community
Community Notebook
Zgłoś jeśli
naruszono regulamin