PLease help a newbie with a complex type and element interaction

S

Sandie C

please help a newbie I am so confused by trying to declare a user type, and
then incorporate it into an element that uses the derived type and has an
attribute.
I have included my schema and xml file below. I am using xml spy and the
message I get is Phone must be valid with respect to definition '{no name}'.
Thanks for any help at all.
Sandie

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:simpleType name="LType">

<xsd:restriction base="xsd:string">

<xsd:enumeration value="home"/>

<xsd:enumeration value="business"/>

</xsd:restriction>

</xsd:simpleType>

<xsd:simpleType name="PType">

<xsd:restriction base="xsd:string">

<xsd:pattern value="[1-9] {3}[0-9]{3}-[0-9]{4}"/>

</xsd:restriction>

</xsd:simpleType>

<xsd:element name="Phone">

<xsd:complexType>

<xsd:simpleContent>

<xsd:extension base="PType">

<xsd:attribute name="Location" type="LType"/>

</xsd:extension>

</xsd:simpleContent>

</xsd:complexType>

</xsd:element>

<xsd:element name="Group">

<xsd:complexType>

<xsd:sequence>

<xsd:element name="Member" maxOccurs="unbounded"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element name="Member">

<xsd:complexType>

<xsd:sequence>

<xsd:element ref="Phone" maxOccurs="unbounded"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>



the xml file is

<?xml version="1.0"?>

<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\0s\test.xsd">

<Member>

<Phone Location="home">305 555-2919</Phone>

<Phone Location="business">305 555-2910</Phone>

</Member>

<Member>

<Phone Location="home">517 555-8911</Phone>

</Member>

<Member>

<Phone Location="home">481 555-0911</Phone>

<Phone Location="home">481 555-0912</Phone>

<Phone Location="home">481 555-0913</Phone>

<Phone Location="business">481 555-8717</Phone>

</Member>

<Member>

<Phone Location="home">305 555-8551</Phone>

<Phone Location="business">305 555-9090</Phone>

</Member>

<Member>

<Phone Location="business">415 555-5313</Phone>

</Member>

<Member>

<Phone Location="home">441 555-8771</Phone>

</Member>

<Member>

<Phone Location="business">305 555-0817</Phone>

</Member>

<Member>

<Phone Location="home">301 555-0914</Phone>

<Phone Location="home">301 555-0915</Phone>

<Phone Location="home">301 555-0916</Phone>

</Member>

<Member>

<Phone Location="home">301 555-3181</Phone>

<Phone Location="business">301 555-6581</Phone>

</Member>

<Member>

<Phone Location="business">301 555-6866</Phone>

</Member>

</Group>
 
P

Priscilla Walmsley

Hi,

I think you want to move the space in your regular expression to after
the {3}, as in:

[1-9]{3} [0-9]{3}-[0-9]{4}

The way you had it, it was expecting one number, then three spaces.

Hope that helps,
Priscilla
 
C

C. M. Sperberg-McQueen

Sandie C said:
I have included my schema and xml file below. I am using
xml spy and the message I get is Phone must be valid
with respect to definition '{no name}'.

What is it that you don't understand?

The Phone element needs to be valid against its type; in the
schema/instance pair you provide, the Phone elements aren't
valid. The type assigned to Phone has no name; that might be
why XML Spy refers to it using the phrase "{no name}".

If that's the only error message you get, I can understand
being a bit baffled; it gives no hint as to WHY the Phone
elements are not valid. You might try another schema
processor. If you don't have any other processors installed,
try packaging up schema and instance together and using the
validate-uploaded-file feature of the XSV server at W3C:
http://www.w3.org/2001/03/webdata/xsv

To package the schema and instance together, make a
file with the following structure:

<wrapper>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
id="this_is_the_place"... (the rest of your schema, just as you sent it
to the newsgroup)
</xsd:schema>
<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="#this_is_the_place">
... (the rest of your XML instance, just as you
sent it to the group)
</Group>
</wrapper>

Put this somewhere in your file system. Then go to
http://www.w3.org/2001/03/webdata/xsv in your Web browser
and scroll down to find the part of the form that begins

Use this form only if you are behind a firewall or have a
schema to check which is not accessible via the Web.

File to upload:

and ask XSV to validate the single-file package you
constructed above.

You'll see a slightly different set of error messages.

They may help convince you that Priscilla Walmsley was
right in her response to your post: your regex is not
doing quite what a regex intended to match North
American phone numbers should be doing.
<xsd:pattern value="[1-9] {3}[0-9]{3}-[0-9]{4}"/>
...
<Phone Location="home">305 555-2919</Phone>

Look at these two carefully and you will achieve
enlightenment.

I hope this helps,

-C. M. Sperberg-McQueen
World Wide Web Consortium
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top