• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

xml DTD

Hi,

I have xml input file as below. I would like to apply below rules.
1. Gender only have input Male/Female, else flag error.
2. Dept only have input Finance/Engineering

<Person>    
      <Manager>
        <Details>
             <option detail="Name"          value="Jone" />
               <option detail="Gender"            value="Male" />
                <option detail="Dept"           value="Finance" />
        </Details>
      </Manager>
      <Employee>  
        <Details>
             <option detail="Name"          value="Alice" />
               <option detail="Gender"            value="Female" />
                <option detail="Dept"           value="Finance" />
        </Details>        
      <Employee>
<Person>

Is the Schematron is the only way to do it?
If I restructure the xml file as below, will it help?

<Person>    
      <Manager>
        <Details>
             <Name>Jone</Name>
               <Gender>Male</Gender>
                <Dept>Finance</Dept>
        </Details>
      </Manager>
      <Employee>  
        <Details>
             <Name>Alice</Name>
               <Gender>Female</Gender>
                <Dept>Finance</Dept>
        </Details>        
      <Employee>
<Person>

Can I have the DTD below to check the gender and dept? will it work?
<?xml version="1.0" encoding="utf-8" ?>
<!ELEMENT Person (Manager, Employee)>
<!ELEMENT Manager  (Details)+ >
<!ELEMENT Employee (Details)+ >
<!ELEMET Details (Name, Gender, Dept)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Gender (Female|Male) >
<!ELEMENT Dept (Finance|Production)>

thanks
pupuboo
0
pupuboo
Asked:
pupuboo
  • 2
1 Solution
 
Geert BormansCommented:
Hi pupuboo,
> Is the Schematron is the only way to do it?

yes,
if you want the value to be restricted to male or female if the other attribute is "gender",
you have a co-occurence constraint
so you need schematron

>If I restructure the xml file as below, will it help?

yes, that can be expressed with DTD
(except the content restriction in the element content)
W3C schema can have an enumeration in the element content
DTDs can only have that in attribute values

This XML can be restricted in DTDs

<Person>    
      <Manager>
        <Details>
             <Name>Jone</Name>
               <Gender value="Male"/>
                <Dept value="Finance" />
        </Details>
      </Manager>
      <Employee>  
        <Details>
             <Name>Alice</Name>
                <Gender value="Female"/>
                <Dept value="Finance" />
        </Details>        
      <Employee>
<Person>

This would be the DTD

<?xml version="1.0" encoding="utf-8" ?>
<!ELEMENT Person (Manager, Employee)>
<!ELEMENT Manager  (Details)+ >
<!ELEMENT Employee (Details)+ >
<!ELEMET Details (Name, Gender, Dept)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Gender EMPTY>
<!ATTLIST Gender
        value (Female|Male) #REQUIRED>
<!ELEMENT Dept EMPTY>
<!ATTLIST Dept
        value (Finance|Production) #REQUIRED>

Cheers!
0
 
pupubooAuthor Commented:
Thanks.
0
 
Geert BormansCommented:
welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now