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
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
9 replies · 3K views
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.
 
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:
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?
 
Mark44: The <sequence> indicator specifies that the child elements must appear in a specific order.