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

  • Thread starter camel-man
  • Start date
  • Tags
    xml
In summary: <xs:element type="xs:string" name="name"/> <xs:element type="xs:string" name="email"/> <xs:element type="xs:string" name="homepage"/>
  • #1
camel-man
76
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
  • #2
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:
  • #3
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:
  • #4
Please don't multi-post the same problem both here and in the homework subforums.
 
  • #5
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.
 
  • #6
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?
 
  • #7
In case you saw the post I just deleted, disregard it. I wasn't understanding the role of sequence in a complexType element.
 
  • #8
Mark44: The <sequence> indicator specifies that the child elements must appear in a specific order.
 
  • #9
See if you can find something similar at the w3wschools link I posted earlier.
 
  • #10

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

What is XML?

XML stands for Extensible Markup Language. It is a markup language used for storing and transporting data. It is used to structure, store, and transport data between different systems.

What is a schema in XML?

A schema in XML is a set of rules that defines the structure and content of an XML document. It is used to validate the data in an XML document and ensure that it conforms to a specific format.

What is the purpose of XML?

The purpose of XML is to provide a standard format for storing and exchanging data. It allows different systems to communicate with each other by using a common language for data representation.

What is the difference between XML and HTML?

The main difference between XML and HTML is that XML is used for storing and transporting data, while HTML is used for creating web pages. XML is a markup language that focuses on data, while HTML is a markup language that focuses on presentation.

What is the role of a DTD in XML?

DTD stands for Document Type Definition. It is used to define the structure and content of an XML document. It specifies the rules for the elements and attributes in the document and ensures that the document is well-formed.

Similar threads

  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Sci-Fi Writing and World Building
Replies
21
Views
1K
  • Programming and Computer Science
Replies
29
Views
3K
  • Programming and Computer Science
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
31
Views
11K
  • Introductory Physics Homework Help
Replies
1
Views
1K
Replies
4
Views
2K
Replies
4
Views
1K
Back
Top