docbook: Thread: Variables in an SGML or XML document


[<<] [<] Page 1 of 1 [>] [>>]
Subject: Variables in an SGML or XML document
From: "Rodolfo J. Paiz" ####@####.####
Date: 15 Nov 2003 22:16:51 -0000
Message-Id: <6.0.0.22.0.20031115155431.024bd480@mail.paiz.org>

Hi!

Can I define a variable in an SGML or XML document, like $TITLE for instance?

I would like to create a standardized block with which to start any HOWTO 
document (including intro, copyright, credits, disclaimers, etc.) and of 
course this would be easier if I could include something like 
TITLE="Nailbiting-HOWTO" and then refer to <title>$TITLE</title> later.

Is this possible, and (if so) is there a difference between how it is done 
in SGML vis-à-vis XML?

Thanks in advance,


-- 
Rodolfo J. Paiz
####@####.####

Subject: Re: Variables in an SGML or XML document
From: "Martin A. Brown" ####@####.####
Date: 15 Nov 2003 22:26:09 -0000
Message-Id: <Pine.LNX.4.58.0311151616190.4453@copula.wonderfrog.net>

Rodolfo,

Hi again!

 : Can I define a variable in an SGML or XML document, like $TITLE
 : for instance?
 :
 : I would like to create a standardized block with which to start any HOWTO
 : document (including intro, copyright, credits, disclaimers, etc.) and of
 : course this would be easier if I could include something like
 : TITLE="Nailbiting-HOWTO" and then refer to <title>$TITLE</title> later.
 :
 : Is this possible, and (if so) is there a difference between how it is done
 : in SGML vis-à-vis XML?

I can't speak for SGML (although I gather it's quite similar).  Here
goes for XML:

You are looking to use entities....general entities.  I use them
frequently in my linux-ip guide (which, though underway, has seen
little work in a few months).

There may be better places to read about general entities, but you
can use the following as an example:

<?xml version='1.0'?>
<!DOCTYPE book PUBLIC
  "-//OASIS//DTD DocBook V4.2//EN"
  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [

  <!ENTITY % my-entities   SYSTEM   "file-full-of-entities.ent" >

    %my-entities;

]>

And then the file "file-full-of-entities.ent" contains lines that
look like this:

<!ENTITY % versioninfo        SYSTEM   "versioninfo.ent"       >
%versioninfo;        <!-- all version stuff in file called
                          versioninfo.ent -->

<!ENTITY iproute2      "<command>iproute2</command>"    >

Now, anytime I use the general entity "&iproute2;" in my document,
it is replaced with the string "<command>iproute2</command>".  This
is convenient for exactly the reason you expressed.

See also all sorts of documents in TLDP CVS.  I'll point you to mine
although others also use entities, I'm sure.

  http://cvs.tldp.org/index.cgi/LDP/guide/docbook/linux-ip/

In particular you may find the file linux-ip.ent interesting.

Best of luck,

-Martin

--
Martin A. Brown --- Wonderfrog Enterprises --- ####@####.####
Subject: Re: Variables in an SGML or XML document
From: Emma Jane Hogbin ####@####.####
Date: 15 Nov 2003 22:33:11 -0000
Message-Id: <20031115223203.GA3160@debian>

On Sat, Nov 15, 2003 at 03:57:32PM -0600, Rodolfo J. Paiz wrote:
> Can I define a variable in an SGML or XML document, like $TITLE for 
> instance?

Yes. In SGML/XML land they're called "entities." You create them at the
very beginning of your document in the document type declaration. Here are
some of the entities that are used in the Author Guide:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [

<!-- Chapter One: About this guide -->
<!ENTITY ag-about SYSTEM "ag-about.xml">
<!ENTITY tldp SYSTEM "tldp.xml">

<!-- Text Macros -->
<!ENTITY conectivasa '<ulink url="http://www.conectiva.com">Conectiva S.A.</ulink>'>
]>


You add the entities inside the DOCTYPE tag with square brackets. You can 
point to other file:
	<!ENTITY shortcut SYSTEM "filename"> 
or you can put the value right in the entity definition:
	<!ENTITY shortcut "Replace 'shortcut' with this text.">

To use them you would call them up with &entityname;. The three entities
above would be used in your document with:
	&ag-about;
	&tldp;
	&conectivasa;

I hope that helps!
emma

-- 
Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]
Subject: Re: Variables in an SGML or XML document
From: "Rodolfo J. Paiz" ####@####.####
Date: 15 Nov 2003 23:34:37 -0000
Message-Id: <6.0.0.22.0.20031115173308.024bea70@mail.simpaticus.com>

At 16:32 11/15/2003, Emma Jane Hogbin wrote:
>Yes. In SGML/XML land they're called "entities." [...]
>
>You add the entities inside the DOCTYPE tag with square brackets. You can
>point to other file:
>         <!ENTITY shortcut SYSTEM "filename">
>or you can put the value right in the entity definition:
>         <!ENTITY shortcut "Replace 'shortcut' with this text.">

Thanks; that last one is precisely what I wanted to do!


-- 
Rodolfo J. Paiz
####@####.####

[<<] [<] Page 1 of 1 [>] [>>]


  ©The Linux Documentation Project, 2014. Listserver maintained by dr Serge Victor on ibiblio.org servers. See current spam statz.