1

This question has been asked before but none of the solutions have worked for me.

Below is an exact question but the solution didn't worked for me.

Question

Here's the problem.

I have the following XML file.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xsl/excerpt.xsl"?>
<category xmlns="http://www.w3schools.com/RedsDevils"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="excerpt.xsd">
  <article>
    <title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
    <excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
    <author>Melanie Pinola</author>
    <date>Dec 20, 2013, 11.00 PM GMT</date>
    <thumbnail>img/food.jpg</thumbnail>
    <link>article1.xml</link>
  </article>
  <article>
    <title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
    <excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
    <author>Melanie Pinola</author>
    <date>Dec 20, 2013, 11.00 PM GMT</date>
    <thumbnail>img/food.jpg</thumbnail>
    <link>article1.xml</link>
  </article>
  <article>
    <title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
    <excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
    <author>Melanie Pinola</author>
    <date>Dec 20, 2013, 11.00 PM GMT</date>
    <thumbnail>img/food.jpg</thumbnail>
    <link>article1.xml</link>
  </article>
  <article>
    <title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
    <excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
    <author>Melanie Pinola</author>
    <date>Dec 20, 2013, 11.00 PM GMT</date>
    <thumbnail>img/food.jpg</thumbnail>
    <link>article1.xml</link>
  </article>
</category>

I am trying to apply the following schema file to above XML file.

 <?xml version="1.0" encoding="utf-8"?>
    <xs:schema targetNamespace="http://www.w3schools.com/RedsDevils"
        elementFormDefault="qualified"
        xmlns="excerpt.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="category">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="article" minOccurs="1" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="title" type="xs:string" minOccurs="1" />
                <xs:element name="excerpt" type="xs:string" minOccurs="1" />
                <xs:element name="author" type="xs:string" minOccurs="0" />
                <xs:element name="date" type="xs:string" minOccurs="0" />
                <xs:element name="thumbnail" type="xs:string" minOccurs="1" />
                <xs:element name="link" type="xs:string" minOccurs="1"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

    </xs:schema>

But its not working. I don't see any errors just the blank page.

Can anyone please help me with this?

Right now both XML and XSD files are in the same directory but I want to move the XSD file to XSD folder. What changes would I have to make for this?

Thanks in advance.

Community
  • 1
  • 1
Jay Bhatt
  • 5,601
  • 5
  • 40
  • 62
  • @mzjn I am trying to display the XML described above using XSLT transformation. This is working fine. But I need to prepare a structure for the XML which I am doing using schema and which isn't working. When I run the final transformed page I don't see anything. If I remove the schema it works. The XML in the question has a link to XSLT and that's why I had added the XSLT tag. – Jay Bhatt Dec 23 '13 at 11:15

1 Answers1

1

I discovered the following validation error

SchemaLocation: schemaLocation value = 'excerpt.xsd' must have even number of URI's.

This was fixed as follows:

<category xmlns="http://www.w3schools.com/RedsDevils" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.w3schools.com/RedsDevils excerpt.xsd">

This might explain why it's considered an invalid XML document, but don't know why this would affect the XSLT transformation. Unless the browser is silently validating the doc.

Extra

There is also a lint violation reported for your schema. Doesn't appear to cause any problems but worth fixing (just remove the xmlns attribute):

$ xmllint excerpt.xsd
RedsDevils.xsd:2: namespace warning : xmlns: URI excerpt.xsd is not absolute
<xs:schema xmlns="excerpt.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targe

                          ^
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Looks like it's the incorrect xsi:schemaLocation that's causing the problem, but if you're not seeing any error message then there's an underlying problem in the way you have configured the validation task. – Michael Kay Dec 23 '13 at 12:52