Newbie's questions

B

Bhushit Joshipura

Question 0:
In case all I am interested in is text manipulation, do I have to
define a style sheet using XSLT? I did not get the style-sheet concept
very well. Any help?

Question 1:
My needs:
1. Embedded tags within a programming language comments
2. Use these tags to identify parts of the code
3. Use the code text for manipulation
4. I may need more type of tags

seem to be satisfied by XML. However, from online tutorials, it was
not clear whether it is legal to use unenclosed text inside an xml
document. For example if the document contents were:

What happens to <root> ... <\root> me?

Question 2:
From http://www.w3schools.com tutorial I understood that text within
tags must not have a < or an & . Is this so or I need to revisit
tutorials? They suggest to use some &lt; thing. I imagine a code like
this:

/* <if> */
if /*<condition>*/(a < b)/*<\condition>*/ \
/*<action>*/printf ("a was less than b\n");/*<\action>*/
/* <\if> */

is illegal because of a < b. Am I in my senses?

-Bhushit
 
T

Tad McClellan

Bhushit Joshipura said:
Question 0:
In case all I am interested in is text manipulation, do I have to
define a style sheet using XSLT?


No. There are many programming languages that can parse XML
and manipulate text.

Any help?


With what?

Question 1:
from online tutorials, it was
not clear whether it is legal to use unenclosed text inside an xml
document. For example if the document contents were:

What happens to <root> ... <\root> me?


Question 2:
From http://www.w3schools.com tutorial I understood that text within ^^^^^^
tags must not have a < or an & . Is this so or I need to revisit ^^^^
tutorials? They suggest to use some &lt; thing. I imagine a code like
this:

/* <if> */
if /*<condition>*/(a < b)/*<\condition>*/ \
/*<action>*/printf ("a was less than b\n");/*<\action>*/
/* <\if> */


(the slashes on your end tags are all leaning the wrong way...)

is illegal because of a < b. Am I in my senses?


Yes it is invalid ("illegal") because of a < b.

Note also that the a < b is NOT within a tag.

http://www.ucc.ie:8080/cocoon/xmlfaq#makeup

You may need to use "CDATA sections", where you _can_ have those
characters, for the code parts.




What is it that you are really trying to accomplish?

Your code above just looks horrid. I'd go crazy if I had to
debug a program that looks like that, even with automated help.

It would be really easy to transform:

<if> <condition>(a < b)</condition>
<action>printf ("a was less than b\n");</action>
</if>

into the code you show above (but that's "too ugly" too).
 
J

Jurrie

Question 0:
In case all I am interested in is text manipulation, do I have to
define a style sheet using XSLT? I did not get the style-sheet concept
very well. Any help?

For "text manipulation" you use XSLT
Question 1:
My needs:
1. Embedded tags within a programming language comments
2. Use these tags to identify parts of the code
3. Use the code text for manipulation
4. I may need more type of tags

seem to be satisfied by XML. However, from online tutorials, it was
not clear whether it is legal to use unenclosed text inside an xml
document. For example if the document contents were:

What happens to <root> ... <\root> me?

That is wrong. for two reasons:
All contents must be inside tags.
Closing a tag is done with '/' and not '\'
the above should be something like:

Question 2:
From http://www.w3schools.com tutorial I understood that text within
tags must not have a < or an & . Is this so or I need to revisit
tutorials? They suggest to use some &lt; thing. I imagine a code like
this:

/* <if> */
if /*<condition>*/(a < b)/*<\condition>*/ \
/*<action>*/printf ("a was less than b\n");/*<\action>*/
/* <\if> */

is illegal because of a < b. Am I in my senses?

yes < should be replaced with &lt;, & with &amp;
You can also use their values for the character (unicode) so you can
also replace & with &

Hope this helps,

Jurrie
 
T

Tad McClellan

Jurrie said:
All contents must be inside tags.


Content is *never* inside tags.

If it is inside of a tag, then it is markup rather than content.

Content is inside elements (ie. between a start tag and an end tag).
 
B

Bhushit Joshipura

Thanks for the reply.
1. I learn it is should not be \ but / in the end tag
2. XSLT is not needed to parse XML document
3. All the text has to be enclosed within some kind of tags
4. < and & inside content are a "no-no"

(and that code was something I came up to give an example.)

Here is a sequel.

I am having lot of TCL code. The TCL code is bound to have < and & as
part of logic.

I want to tag it using XML and then manipulate the TCL code based on
sections identified. I plan XML tags within TCL comments. Thus my file
will serve dual role - as a TCL file and an XML file.

If it is illegal to have contents with < and & inside XML document, I
am breaking either TCL (by replacing those symbols) or XML (by not
replacing those symbols).

I must not be the first person to face this and must not be the last.
Is there a solution?

-Bhushit
 
M

Martin Boehm

I am having lot of TCL code. The TCL code is bound to have < and & as
part of logic.
I want to tag it using XML and then manipulate the TCL code based on
sections identified. I plan XML tags within TCL comments.

How do you want to do that?

An XML file starting with a TCL comment would be illegal.
A TCL file starting with XML Elements would be illegal.
Thus my file will serve dual role - as a TCL file and an XML file.

You cannot wrap the one thing transparently into the other, whithout
producing side effects.
If it is illegal to have contents with < and & inside XML document, I
am breaking either TCL (by replacing those symbols) or XML (by not
replacing those symbols).

I don't think XML is what you want or need. If you want to use it, you
have make a parser converting your code into XML, pack it between 'tags'
and live with it. You may also use CDATA sections, which are able to
hold any character data, even XML specific symbols. Either way, what you
will get will be far from TCL code.
I must not be the first person to face this and must not be the last.

I guess you are. ;-)

Martin
 
P

Patrick TJ McPhee

[...]
% sections identified. I plan XML tags within TCL comments. Thus my file
% will serve dual role - as a TCL file and an XML file.

% If it is illegal to have contents with < and & inside XML document, I
% am breaking either TCL (by replacing those symbols) or XML (by not
% replacing those symbols).

It seems unlikely that you can come up with one file which is both
syntactically correct XML and TCL.

The normal thing is to either have an XML file with TCL code in some
sections, or to have a TCL program with XML mark-up in the comments.
In either case, you need a program to extract either the TCL or the
comments. Consider, for instance, http://xmLP.sf.net, a literate
programming tool written in xslt.

There are two ways to encode programming languages which use < and
& in XML documents. You can include the code in a CDATA section

<program><[CDATA[
if x < y then say 'x is less than y'
]]><program>

The only thing you have to watch for in that case is `]]>'. If you
need to use this combination in your program, then you have to
end the CDATA section.

<program><[CDATA[if x < y then say 'x is less than y']]>
else if z = ']]>' then do
say 'you shouldn't use combinations like' z 'in programs which'
say 'have been embedded in XML documents
end
<program>

The first ]]> ends the CDATA section, the next ]]> is part of the content.
If I had more > or & coming up, I would have started a new CDATA section.
I ended the section a few characters before I had to because it's probably
easier to edit in a structured editor if you keep complete lines in the
CDATA sections.

Of course, in a structured editor, it's trivial to use &amp; and &lt;

<program>if x &lt; y then say 'x is less than y'</program>

that's not nice if you work with people who choose to edit the XML
directly. I prefer using CDATA sections, and I generally never use
]]> in the programs themselves, so there's no real problem.

Another thing you can do is rearrange tests so that you
never test for one value being less than another

<program>if y > x then say 'x is less than y'</program>

This code is Rexx, because I don't like TCL, but the same principles
apply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top