Need help with XML and Schemas for creating a complex photo gallery?

  • Thread starter Thread starter camel-man
  • Start date Start date
  • Tags Tags
    xml
Click For Summary

Discussion Overview

The discussion revolves around creating an XML file for a complex photo gallery, including the development of an XML Schema (XSD) to validate the structure of the XML. Participants are exploring how to represent various elements of photos, including metadata and creator information, while addressing issues related to optional elements and validation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses uncertainty about their XML structure and seeks feedback on their progress.
  • Another participant questions whether a file containing the schema was intended to be attached.
  • A participant shares their XML and XSD code, asking for validation against their schema.
  • Concerns are raised about the handling of optional elements in the schema, with a suggestion to use the minOccurs attribute to make elements optional.
  • A participant seeks clarification on how to add multiple photo elements to their XML file while maintaining validation with the XSD.
  • Discussion includes a clarification about the role of the indicator in defining the order of child elements within a complex type.
  • Participants share links to resources for learning XML and XSD, with differing opinions on the quality of the materials.

Areas of Agreement / Disagreement

Participants generally agree on the need for a structured approach to XML and XSD creation, but there are differing views on the adequacy of certain learning resources and the handling of optional elements in the schema. The discussion remains unresolved regarding the best practices for validating multiple photo entries in the XML.

Contextual Notes

Some participants note that certain elements in the XML schema should be optional, but the specifics of how to implement this remain unclear. There is also a lack of consensus on the best resources for learning XML and XSD.

camel-man
Messages
76
Reaction score
0
I Need to create an xml file that involves having a gallery root element and photos inside that have multiple elements to them. I am not quite sure if I am doing anything right because I am so new to xml and there are not much tutorials out that are helpful.

instructions:
Extend your XML representation of photos in three ways:
a. The creator of a photo is now more than a name, it's a complex type <creator>
with three subelements: the name (as before), an optional email and an
optional homepage.
b. Photos are getting some more properties: A photo also has
• a title which is a string,
• a copyright which is also a string
c. Photos are collected in a gallery element

Develop an XML Schema that captures this new structure

Can someone view my current progress and tell me if I am on track thank you.

P.S. I am also using Netbeans to create and write these documents.
 
Technology news on Phys.org
camel-man said:
I Need to create an xml file that involves having a gallery root element and photos inside that have multiple elements to them. I am not quite sure if I am doing anything right because I am so new to xml and there are not much tutorials out that are helpful.

instructions:
Extend your XML representation of photos in three ways:
a. The creator of a photo is now more than a name, it's a complex type <creator>
with three subelements: the name (as before), an optional email and an
optional homepage.
b. Photos are getting some more properties: A photo also has
• a title which is a string,
• a copyright which is also a string
c. Photos are collected in a gallery element

Develop an XML Schema that captures this new structure

Can someone view my current progress and tell me if I am on track thank you.
Did you intend to attach a file with your schema definition?
camel-man said:
P.S. I am also using Netbeans to create and write these documents.
You can use an ordinary text editor to create your schema definition (XSD) file.

Here's a link to a site that has some pretty good tutorials - http://www.w3schools.com/Schema/default.asp . I have found them very helpful resources for learning CSS (cascading style sheets) and HTML.
 
Last edited by a moderator:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<gallery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Schema.xsd">

      <photo>
        <title>first</title> 
        <copyright>CC BY-ND</copyright>
        <creator>
            <name>John Smithr</name>
            <email>Joker123@yahoo.com</email>
            <homepage></homepage>
        </creator>
        <mimetype>image/png</mimetype>
        <location>[PLAIN]http://cache.ohinternet.com/images/thumb/2/2d/Trollface_HD.png/618px-Trollface_HD.png</location>[/PLAIN] 
        <width>618</width>
        <height>564</height>
        <keywords>
            <keyword>blackandwhite</keyword>
            <keyword>trolling</keyword>
            <keyword>face</keyword>
        </keywords>
        </photo>
    
</gallery>

That is my XML file and I do not know if my schema is on par with it... any help would be appreciated.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="gallery">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="photo">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="title"/>
                            <xs:element type="xs:string" name="copyright"/>
                            <xs:element name="creator">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element type="xs:string" name="name"/>
                                        <xs:element type="xs:string" name="email"/>
                                        <xs:element type="xs:string" name="homepage"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element type="xs:string" name="mimetype"/>
                            <xs:element type="xs:anyURI" name="location"/>
                            <xs:element type="xs:short" name="width"/>
                            <xs:element type="xs:short" name="height"/>
                            <xs:element name="keywords">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element type="xs:string" name="keyword" maxOccurs="unbounded" minOccurs="0"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>            
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
 
Last edited by a moderator:
Please don't multi-post the same problem both here and in the homework subforums.
 
This looks like a good start, but you haven't taken into account that some of the elements are optional. Here is some code copied from the site whose link I gave earlier.
Code:
<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string" maxOccurs="10"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

To make something optional, set minOccurs to 0.
 
Ahh, thank you. Now that my XML file validates with my XSD file, how can I add onto the original XML file, for example I want to add 2 more photo elements. I tried putting in the same code 2 more times for my XML but then it does not validate correctly with my XSD. What is the catch here?
 
In case you saw the post I just deleted, disregard it. I wasn't understanding the role of sequence in a complexType element.
 
Mark44: The <sequence> indicator specifies that the child elements must appear in a specific order.
 
See if you can find something similar at the w3wschools link I posted earlier.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
29
Views
6K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 31 ·
2
Replies
31
Views
12K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K