Is this really xml-standard?

G

Gert Mellak

Hi!

I'm writing an online-shop that receives data-updates about the
company's products as xml-files. I'm not sure about the Group-Tags -
is this really xml-standard?? They should represent the article-groups
I have to use in my online shop. Here's the file:

<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Group>
Group 1
<Group>
Group 2
<Group>
Group 3
<Group>
Group 4
</Group>
</Group>
</Group>
</Group>
</Article>
</Data>

Thank you for your help!

Greetings,
Gert.
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

Gert said:
I'm writing an online-shop that receives data-updates about the
company's products as xml-files. I'm not sure about the Group-Tags -
is this really xml-standard?? They should represent the article-groups
I have to use in my online shop. Here's the file:

xmllint reports no error with your example data.

I would be interested to know why you use XML files
for storing your data ? What is the advantage ?
Or is it just that the word XML sounds so nice ?
 
G

Gert Mellak

I'm developing an online shop and the agreed strategy is that I get the
data out of the company's database stored within xml-files. I think it's
not a bad idea since finally the data-structures will be quite complex
and there are many hierarchical structures...

greetings,
Gert.
 
G

Gert Mellak

xml was the suggested method from the company's adminstrator. I take the
files and import the data into my database.

We thought about using ini-files or csv at first, but since the data
will get quite complex with many hierarchical structures we decided to
transmit it within xml-files.

What would you have used instead?
 
M

Marrow

Hi Gert,

Not sure what you mean by "is this really xml-standard??" - so long as an
XML document is well-formed then it meets the 'standard' in that in complies
with the W3 specs and will be able to be read by a parser.

As to whether the structure if your XML is the best idea - this depends
really on what you are doing. But at first glance, the structure you have
where <Group> elements are nested within each other looks a little odd...
you have (tidied)...

<?xml version="1.0"?>
<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Group>Group 1
<Group>Group 2
<Group>Group 3
<Group>Group 4</Group>
</Group>
</Group>
</Group>
</Article>
</Data>

So to get at the list of <Group>'s for a given article may prove a little
tricky - and probably more difficult than it needs be. By nesting them in
this way you are also mixing text nodes (i.e. the text "Goup 1") with child
elements - although this is permissable in XML most people try to avoid
doing it unless it is neccessary.

So perhaps you should consider a structure more like...

<?xml version="1.0"?>
<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Group>Group 1</Group>
<Group>Group 2</Group>
<Group>Group 3</Group>
<Group>Group 4</Group>
</Article>
</Data>

And it is sometimes recommened that repeating elements are nested within a
holder element (which often makes defining a Schema/DTD a little easier and
can also have performance advantages when querying the document), e.g.

<?xml version="1.0"?>
<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Groups>
<Group>Group 1</Group>
<Group>Group 2</Group>
<Group>Group 3</Group>
<Group>Group 4</Group>
</Groups>
</Article>
</Data>


HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

Gert said:
xml was the suggested method from the company's adminstrator. I take the
files and import the data into my database.

External needs seem acceptable to me.
Especially because conventions about content
are usually established in the form of DTDs
or Schemata.
We thought about using ini-files or csv at first, but since the data
will get quite complex with many hierarchical structures we decided to
transmit it within xml-files.

You seem to have the infrastructure for supporting
conventions like DTDs.
What would you have used instead?

Depends on what one is doing. CSV works in many cases
if the problem is not too complex. My impression (and
the reason for asking) is that many people start using
XML without knowing the consequences of this decision.
If you work in an environment where the infrastructure
is established, then XML seems OK.

I have seen examples where a single developer started
"inventing" ad hoc structures for simple configuration
files. Such people ignored to write and support proper
DTDs and really did not care about other people who
have to read or write such configuration files. As a
consequence, handling these configuration files has
become really painful.
 
P

Peter Flynn

Gert said:
Hi!

I'm writing an online-shop that receives data-updates about the
company's products as xml-files. I'm not sure about the Group-Tags -
is this really xml-standard?? They should represent the article-groups
I have to use in my online shop. Here's the file:

<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Group>
Group 1
<Group>
Group 2
<Group>
Group 3
<Group>
Group 4
</Group>
</Group>
</Group>
</Group>
</Article>
</Data>

It's fine, and enclosing all the elements belonging to one article is
exactly the right way to do it.

However, I'm not clear what the Group elements achieve all nested like
that, with character data and further Group elements mixed into them.
It's normally regarded as very poor design for data-oriented applications.
I am guessing that the Group data should almost certainly NOT be nested
unless it really does have some hierarchical meaning.

If you mean that Article 3746 belongs to Groups 1, 2, 3, and 4, you might
consider:

<Article Number="3746">
<Description>This is the article description</Description>
<Group N="1"/>
<Group N="2"/>
<Group N="3"/>
<Group N="4"/>
</Article>

If the Group data really is hierarchical, then add an element within each
Group element to hold the text: do NOT intermingle text and elements (keep
that style for textual applications like books where mixed content has its
real value):

<Article Number="3746">
<Description>This is the article description</Description>
<Group N="1">
<Description>Group 1 text</Description>
<Group N="2">
<Description>Group 2 text</Description>
<Group N="3">
<Description>Group 3 text</Description>
<Group N="4">
<Description>Group 1 text</Description>
</Group>
</Group>
</Group>
</Group>
</Article>

That lets you add more elements after the group description before the
start of a subgroup if that becomes necessary.

The choice between attributes and elements is the subject of a lot of
argument, but I recommend using attributes for numeric and categorical
data, and keeping character data content for text. But others may well
disagree with this: it's your choice.

///Peter
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top