Solved

XML vALIDATION

Posted on 2008-10-08
5
262 Views
Last Modified: 2013-11-18
Hi,

I am preparing XSD for some XML file required in my application. Snap shot of the XML is shown here:

<Roles>

            <Role HomeFolder="All Folders\Sales" />

</Roles>

 

 

Specified XML has one attributes: HomeFolder. While preparing XSD, I want to put constraint that attribute value HomeFolder should have atlest some value in it. It should not just have white spaces only.

 

For example,

 

HomeFolder="All Folders"                       - Valid

HomeFolder="     All   Folders     "           - Valid

HomeFolder="        "                              - Invalid (tab as whitespace character)

HomeFolder="   "                                   - Invalid (space as whitespace character)

HomeFolder=""                                      - Invalid

Would you please let me know whether it is possible to assign such rules (for attribute) in XSD or not?

0
Comment
Question by:dhiraj79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22667076
For me the most flexible way of dealing with this is by restricting the content of the attribute (a named simple type in this case) with a pattern.
The regular expression in the pattern would then be a series of zero or more whitespace. One non whitespace character and then anything
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Roles">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element name="Role">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="HomeFolder" type="myNotEmptyStringType"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
 <xs:simpleType name="myNotEmptyStringType">
     <xs:restriction base="xs:string">
         <xs:pattern value="\s*[^\s].*"></xs:pattern>
     </xs:restriction>
 </xs:simpleType>
</xs:schema>

Open in new window

0
 

Author Comment

by:dhiraj79
ID: 22667707
Hi Gertone,
Thanks for your reply, but there is a problem
  This is for XSD problem
  the regex you give will accept following:
  "       "
  it will accept string which has only white space characters....
  this is what i dont want to accept
I do not want to accept "" or " " or "     " etc
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 22667783
you are incorrect.
The regex will NOT accept "      ",
because after a series of spaces, at least ONE non-whitespace character is required,
that is what [^\s] does (this means one none whitte-space character)
Have you tested?
I did, and it seems to work with all your examples, as you asked
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22690217
Is meta character \S not defined in XSD regexp pattern?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22718711
to answer zvonko's comment, yes it is. I have a tendency to build character classes the way I did, rather than using \S or other negative build in character classes... just too lazy to change old habbits I assume :-)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question