473,788 Members | 2,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is XML what I want here?

Hi everyone. I thought I might do a little experiment with XML and type
up some rules for syntax formatting for a programming language. But I'm
a little confused about how to format the XML file. My first thought was
I might do this in HTML instead, and I think I sort of wrote the XML
file with HTML syntax in mind. Needless to say, nothing is nested properly:

<?xml version='1.0' encoding='utf-8'?>

<category>Cod e Layout</category>

<subcategory>In dentation</subcategory>
<rule>Use 4 spaces per indentation level.</rule>

<subcategory>Ta bs or Spaces</subcategory>
<rule>Spaces-only are strongly recommended over tabs.</rule>

<subcategory>Ma ximum Line Length</subcategory>
<rule>Limit all lines to a maximum of 79 characters.</rule>
<rule>
For flowing long blocks of text (docstrings or comments), limiting the
length to 72 characters is recommended.
</rule>
<rule>
The preferred way of wrapping long lines is by using Python's implied
line continuation inside parentheses, brackets and braces. If necessary,
you can add an extra pair of parentheses around an expression, but
sometimes using a backslash looks better.
</rule>

My question is, how do I have text within an element like <category>,
which should actually be the entire parent node of the file? Am I not
supposed to have text in it? What would be the proper way to do this?

I am thinking of something like this:

<h1>Code Layout</h1>
<h2>Indentation </h2>
<p>Use 4 spaces per indentation level.</p>

But obviously that isn't the structure of XML, yet I'm after something
like that. I thought XML might be more general, and therefore a little
more flexible to use in a variety of ways, than HTML, but I can't get
the HTML structure out of my head when trying to write the XML file.

Thanks for any help.
Mar 4 '06 #1
7 1409
It depends what you are using it for really? Is it just like an HTML in
that it is purely for displaying data on a webpage or are you trying to
introduce more functionality?

Steve

Mar 4 '06 #2
steve_marjoriba nks wrote:
It depends what you are using it for really? Is it just like an HTML in
that it is purely for displaying data on a webpage or are you trying to
introduce more functionality?

Steve


Well, my original intent was more for display purposes, which is
probably why I thought of HTML first. But then I figured it might be
useful to write it in XML so I can name the nodes properly and can use
it to interact with programs that might need to read from it.

Is it possible to embed the XML into an HTML file? I'm not too familiar
with what, exactly, XHTML does, so I don't know if this is one option.
Mar 4 '06 #3
Look here for an intorduction to XHTML
http://www.w3schools.com/xhtml/default.asp

For just display purposes then use XHTML (or HTML) but if you want to
display the data and have the potential for programs to access the data
within it then I'd recommend that you use XML and use an XSL stylesheet
to transform it for display purposes. There are tutorials for all of
this on that website http://www.w3schools.com

Steve

Mar 4 '06 #4
steve_marjoriba nks wrote:
Look here for an intorduction to XHTML
http://www.w3schools.com/xhtml/default.asp

For just display purposes then use XHTML (or HTML) but if you want to
display the data and have the potential for programs to access the data
within it then I'd recommend that you use XML and use an XSL stylesheet
to transform it for display purposes. There are tutorials for all of
this on that website http://www.w3schools.com

Steve


Thanks, I'll check that out. But one question: will this allow me to add
text to parent nodes? For example, if I have <subcategory> </subcategory>
as the parent to several <rule> nodes, am I still able to put text
within the <subcategory> node? Or does it always just contain child nodes?
Mar 4 '06 #5
You mean like this?

<subcategory>
Text here
<rule />
<rule />
</subcategory>

Yeah, this is possible, it's called a mixed content element.

Steve

Mar 5 '06 #6
John Salerno wrote:
Hi everyone. I thought I might do a little experiment with XML and type
up some rules for syntax formatting for a programming language. But I'm
a little confused about how to format the XML file. My first thought was
I might do this in HTML instead, and I think I sort of wrote the XML
file with HTML syntax in mind. Needless to say, nothing is nested properly:

<?xml version='1.0' encoding='utf-8'?>

<category>Cod e Layout</category>

<subcategory>In dentation</subcategory>
<rule>Use 4 spaces per indentation level.</rule>
This is generally counterproducti ve. XML works on the basis of
hierarchies and containers (think DIVs), so better would be

<subcategory>
<name>Indentati on</name>
<rule>Use 4 spaces per indentation level.</rule>
</subcategory>

However, if you want to use the XML in processing, rather than just
document things, you need to phrase it so a machine can read it:

<subcategory>
<name>Indentati on</name>
<rule class="textinde nt" lang="css" value="4" units="em"/>
</subcategory>

[...] My question is, how do I have text within an element like <category>,
Just type it. But in practice, for an XML document going to be used as
data, mixing text and markup is A Bad Idea. It's normal for text
documents (eg HTML) but for XML-used-as-data is will only lead to tears
and recriminations.
which should actually be the entire parent node of the file? Am I not
supposed to have text in it? What would be the proper way to do this?

I am thinking of something like this:

<h1>Code Layout</h1>
<h2>Indentation </h2>
<p>Use 4 spaces per indentation level.</p>


Not useful.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 5 '06 #7
John Salerno wrote:
steve_marjoriba nks wrote:
Look here for an intorduction to XHTML
http://www.w3schools.com/xhtml/default.asp

For just display purposes then use XHTML (or HTML) but if you want to
display the data and have the potential for programs to access the data
within it then I'd recommend that you use XML and use an XSL stylesheet
to transform it for display purposes. There are tutorials for all of
this on that website http://www.w3schools.com

Steve

Thanks, I'll check that out. But one question: will this allow me to add
text to parent nodes?


Not relevant. Whether or not you can add text to an element's content
depends on the rules (if any) you have established beforehand.

If you use one of the well-known sets of rules like DocBook, then your
ability to add text in any given element depends on whether it has been
made suitable for this or not. Paragraphs <para> can contain mixed
content, for example; list containers like <itemizedlist > can't (but
paragraphs within each <listitem> obviously can).
For example, if I have <subcategory> </subcategory>
as the parent to several <rule> nodes, am I still able to put text
within the <subcategory> node? Or does it always just contain child nodes?


If you decide you can, you can, but as I pointed out earlier, it's
poor practice unless you have some very specific reason for wanting to
intermingle arbitrary text and rule elements.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4322
by: JimC | last post by:
Think I asked this once before. My apologies for asking twice. In a certain PHP document at my site, I have a link to a Word version of the same document. If the user downloads it, I want to log that s/he has done this. Data logging isn't the issue. Calling a PHP script is. So what I have is something like: <a href=http://my-web-site.com/documents/mydoc.doc>Click here</a> to download a Word version of this document.
14
1888
by: lutorm | last post by:
Hi, I'm having a problem with a return statement being parsed to return a function (I think). Check here: template <typename T> class A {}; template <typename T> class maker_of_A { public: A<T>& make_A() {return A<T>();}; };
5
2655
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more demand for. Looking at jobs there seems to be a better chance in getting a java job rather than a oracle or c++ job. Also is java and oracle a good combiantion?
11
2140
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my loading procedure there's a point or two where I'll malloc a struct which I then don't need, and dispose of it; I was wondering if there was some way I could optimize this kludge out of existence: void loadContacts () { int fd, bytesread; if (...
16
2000
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't see how the return value comes to play here. Ex
2
2264
by: karunakar | last post by:
Hi All In datagrid OnMouseOver iam showing some color Onmouseout also working fine . Here my problem is when ever click the pariculat row in DataGrid iam showing red color that time i am not getting any problem . when ever mouse was changed paricular row that time color is lossed "When ever click the particular Row That time i want to show that color & that time dont loss that color( when ever onMouseover changed)" Here it's not...
182
7560
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
3
2670
by: growse | last post by:
Right, I've got a 2 c# programs here. Lets call them A and B. My aim is to send a simple string from B to A. A is always running. I've overridden the WndProc method to give me messages that are sent to it. B is a program that loads, sends a message and then quits. Let me give you the code to B (bits are missed out, but I've got the important stuff there): private const uint WM_USER_SENDTEXT = 0x8001;
3
4516
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After inserting, I want to send the data via email, the problem is how do I do that?
4
4474
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one Project. So let's say I've created a Folder called "MyVBNet Classes" to hold these general-use VB.Net class files that I will eventually associate with various Projects I create. Now let's imagine I've created a class called "MyClass.vb" that...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.