473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to combine element pattern with attributes?

Hi!

How do I combine an element pattern with attributes?

I can validate

<phone>111-111-1111</phone> using

pattern

I can validate presence of attributes

<phone name="xyx" value="123">111-111-1111</phone>

but now I want to validate the content of phone (111-111-1111) using
pattern
and the presence of the attributes name and value.

I am seem to be unable to find the right notation to combine the two

This is one description I think should work but doesn't (tried many
alternatives but haven't found the right one yet...)

<xsd:complexType name="Phone">
<xsd:simpleContent>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
</xsd:restriction>
</xsd:simpleContent>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="value" type="xsd:string" use="optional"/>
</xsd:complexType>

the content of name and value need not be validated, just the presence
as described in the 'use'

This should be simple i guess, but I it click yet in my mind...

any help appreciated!!!

Michael
Jul 20 '05 #1
4 6604
Hi Michael,

You need to do it in two steps:

<xsd:simpleType name="PhoneNumber">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Phone">
<xsd:simpleContent>
<xsd:extension base="PhoneNumber">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="value" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

Hope that helps,
Priscilla
-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
Priscilla,
thanks I got to that structure as well, but Word (Office 2003) does not like
that and complains:
xsd:PhoneNumber not valid ... on the xsd:extensio base= part.

Interesting book on your site, does it cover this sort of stuff?

We are trying to use Word built in XML to validate document based on a
schema.

"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
Hi Michael,

You need to do it in two steps:

<xsd:simpleType name="PhoneNumber">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Phone">
<xsd:simpleContent>
<xsd:extension base="PhoneNumber">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="value" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

Hope that helps,
Priscilla
-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #3


Michael wrote:

I got to that structure as well, but Word (Office 2003) does not like
that and complains:
xsd:PhoneNumber not valid ... on the xsd:extensio base= part.


I have tried the following examples with MSXML 5 (which Office 2003
uses) and I get no problems validating with script:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:simpleType name="PhoneNumber">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="Phone">
<xs:simpleContent>
<xs:extension base="PhoneNumber">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="phone" type="Phone" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

XML instance:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004102501Xsd.x ml">
<phone name="Lance">111-111-1111</phone>
</root>

Maybe someone here can help when you post the complete example causing
the error.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
Hi Michael,

If you're using a target namespace (which I assume you are if you're
using Word 2003), you need to reference the PhoneNumber simple type
using its _qualified_ name.

For example, if you map your target namespace to the prefix xyz, you
would use base="xyz:PhoneNumber", as in:

<xs:schema targetNamespace="http://xyz"
xmlns:xyz="http://xyz"
.....

<xsd:complexType name="Phone">
<xsd:simpleContent>
<xsd:extension base="xyz:PhoneNumber">
....
</xsd:complexType>

Interesting book on your site, does it cover this sort
of stuff?


If you're talking about my schema book (Definitive XML Schema), yes it
covers all this. My other book (XML in Office 2003) covers using Word
with XML in detail, and has a one-chapter overview of XML Schema.

Thanks,
Priscilla
-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Han | last post by:
I know this is possible (because preg can do almost anything!), but can't get a handle on the syntax. I have an HTML string: <font size="3"><a...
1
by: Don Adams | last post by:
I would like to have the following XML: <phone type="work">555-123-1234</phone> <phone type="home">555-123-4321</phone> Is it possible to write a schema to restrict the contents of the type...
2
by: David Nedrow | last post by:
OK, I have a problem which I'm guessing is simply my inability to figure out a select pattern in XSL. I have an XML file similar to the following: <?xml version="1.0"?> <?xml-stylesheet...
1
by: UndoMiel | last post by:
Hi, I have a situation where i would like to validate the occurance of certain elements, based on the value of an attribute. What is the "best" way to handle such validations? I am fairly new...
1
by: Tod Johnson | last post by:
Hello all, Can't figure it out. :( Assume that we have 2 XML document: Document1 (source): <elements> <elementA attribute1="value1" attribute2="value2" ... /> <elementA attribute1="value1"...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
7
by: George Sakkis | last post by:
A situation that often comes up is having to initialize several instance attributes that accept a default value. For a single class, passing the default values in __init__ is fine: class...
3
by: WideBoy | last post by:
Hi, I have a software generated schema which creates a few empty elements, e.g. <xsd:sequence/>. I would like to be able to delete these elements from the schema post-generation using XSLT. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.