Jump to content

Hello everyone, 

 

I am doing a project on xml. Need to do a bookstore xml with xsd, xsl, all that good stuff

 

Was wondering if this is good practice or if there is a better way to do it considering i'll be using the data on functions\variables

 

<Título>Voices from Chernobyl
	<SubTítulo>The Oral History of a Nuclear Disaster</SubTítulo>
</Título>

So I have Título (Title) and SubTítulo (like second title or second part of title), should I have SubTitle has a attribute, some other form?

 

Thanks

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/
Share on other sites

Link to post
Share on other sites

In my understanding, the Title and Subtitle are properties of an object "Movie" so it should look like:
 

<Movie>
  <Title>Something</Title>
  <Subtitle>The last something</Subtitle>
  [...]
</Movie>

I would imagine that it is not technically incorrect, but the more "logical" your code the better effects you will get later.

Try, fail, learn, repeat...

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/#findComment-9889338
Share on other sites

Link to post
Share on other sites

Just now, zwirek2201 said:

In my understanding, the Title and Subtitle are properties of an object "Movie" so it should look like:
 


<Movie>
  <Title>Something</Title>
  <Subtitle>The last something</Subtitle>
  [...]
</Movie>

 

That's what I had But I was trying to add more complexity (hierarchy).

And it is more in the lines of

<Title> Lord of the Rings<Title/>
<SubTitle> The two towers</SubTitle>

But adding layer of hierarchy

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/#findComment-9889348
Share on other sites

Link to post
Share on other sites

33 minutes ago, ShatteredPsycho said:

That's what I had But I was trying to add more complexity (hierarchy).

And it is more in the lines of


<Title> Lord of the Rings<Title/>
<SubTitle> The two towers</SubTitle>

But adding layer of hierarchy

It really depends on how you think about the data. I would think about it in the objective way and for me Subtitle is a property of a movie rather than a title.

 

It is just a logical way for me to access a Subtitle of a Movie as "Movie.Subtitle" than "Movie.Title.Subtitle" and in the same way I would use "Actor.Name" and "Actor.Nickname" rather than "Actor.Name.Nickname".

The other thing that you may want to think about is whether a movie can ever have multiple subtitles. If a movie could have n subtitles then it would be better to store them as:

<Movie>
  <Title> Lord of the Rings</Title>
  <Subtitles>
    <SubTitle> The two towers</SubTitle>
    <Subtitle> The third tower strikes again</Subtitle>
    <Subtitle> For some reason</Subtitle>
    [...]
  </Subtitles>
</Movie>

rather than

<Movie>
  <Title> Lord of the Rings</Title>
  <SubTitle1> The two towers</SubTitle1>
  <Subtitle2> The third tower strikes again</Subtitle2>
  <Subtitle3> For some reason</Subtitle3>
  [...]
</Movie>



 

Try, fail, learn, repeat...

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/#findComment-9889476
Share on other sites

Link to post
Share on other sites

29 minutes ago, zwirek2201 said:

It really depends on how you think about the data. I would think about it in the objective way and for me Subtitle is a property of a movie rather than a title.

 

It is just a logical way for me to access a Subtitle of a Movie as "Movie.Subtitle" than "Movie.Title.Subtitle" and in the same way I would use "Actor.Name" and "Actor.Nickname" rather than "Actor.Name.Nickname".

The other thing that you may want to think about is whether a movie can ever have multiple subtitles. If a movie could have n subtitles then it would be better to store them as:


<Movie>
  <Title> Lord of the Rings</Title>
  <Subtitles>
    <SubTitle> The two towers</SubTitle>
    <Subtitle> The third tower strikes again</Subtitle>
    <Subtitle> For some reason</Subtitle>
    [...]
  </Subtitles>
</Movie>

rather than


<Movie>
  <Title> Lord of the Rings</Title>
  <SubTitle1> The two towers</SubTitle1>
  <Subtitle2> The third tower strikes again</Subtitle2>
  <Subtitle3> For some reason</Subtitle3>
  [...]
</Movie>



 

All right, i'll add up complexity somewhere else. makes more sense like what  you wrote

 

thx

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/#findComment-9889598
Share on other sites

Link to post
Share on other sites

@madknight3 @zwirek2201

How do I go about conditions by attributes? 

Bit of a better explanation, I have this:

<Preço desconto="15">22€</Preço>

Which is basically a discount over a book. Now, in terms of xsd and xsl how do I treat this data? Because it can either be there or not

Link to comment
https://linustechtips.com/topic/784636-xml-good-practices/#findComment-9890786
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×