School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,403 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,632 people online right now. Registration is fast and FREE... Join Now!




Regular Expression for XML attribute

 

Regular Expression for XML attribute

agent_logic

25 Jun, 2009 - 02:51 AM
Post #1

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 29


My Contributions
Hi,

I'm developing an XML Schema as part of my assignment, and one requirement has an "id" attribute which must be *unique*, and must begin with an alphabet, followed by 8 digits. This is what I did:

CODE

<element name="employee">
...
...
<attribute name="id" type="ID">
    <simpleType>
        <restriction base="string">
            <pattern value="[A-Z]{1}[0-9]{8}" />
        </restriction>
    </simpleType>
</attribute>
...
...
</element>


When I validate my xml document, the Xerces-C parser complains that "attribute 'id' cannot have both 'type' attribute and simpleType definition." Is there any other way I can ensure the attribute values would be unique in the xml document, since I apparently can't have a cake and eat it sad.gif?

Thanks in advance.

User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Regular Expression For XML Attribute

25 Jun, 2009 - 03:24 AM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
Do exactly what it says, remove simpleType..
CODE
<attribute name="id" type="ID" />


It's always going to be unique.
User is offlineProfile CardPM
+Quote Post

agent_logic

RE: Regular Expression For XML Attribute

25 Jun, 2009 - 03:32 AM
Post #3

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 29


My Contributions
Hi MageUK,

Thanks for your reply. I know the ID attribute ensures unique values, but there is another constraint which requires that the attribute begin with one alphabet character, followed by 8 digits.
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Regular Expression For XML Attribute

25 Jun, 2009 - 03:38 AM
Post #4

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
Personally I'd just make the application that is going to parse docs around this scheme validate the field themselves.

I took a look around on Google and I don't think there's any other way to do it (Apart from an XPath pattern if that applies, not sure).
User is offlineProfile CardPM
+Quote Post

agent_logic

RE: Regular Expression For XML Attribute

25 Jun, 2009 - 03:51 AM
Post #5

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 29


My Contributions
Yeah, that struck me too. Doing it that way saves you quite a bit of dirty work developing the xml schema! But unfortunately, it's a requirement for my assignment. I might have to take a look at XPath, very new to it.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:31PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month