[xml] XML Schema Help




I have an XML file where I need to check for a particular node value, which is three levels down from it's 
parent node. Basically, I need to ensure that that node value is present but allow other node values as well. 
Is this possible? I've tried numerous attempts without any luck.

[XML FILE]
<root>
<Policy>
    <Preferences>
        <ServerPreferences>
            <preference>
                <name>A</name>
                <value>B</value>
            </preference>
            <preference>
                <name>ATARGETS</name>
                <value>B</value>
            </preference>
        </ServerPreferences>
    </Preferences>
</Policy>
<Report name="">
<ReportHost name="">
<HostProperties>
<tag name="HOST_START"></tag>
<tag name="HOST_END"></tag>
<tag name="mac-address"></tag>
</HostProperties>
<ReportItem port="" svc_name="" protocol="" pluginID="" severity="" pluginName="" pluginFamily="">
<description></description>
</ReportItem>
</ReportHost>
</Report>
</root>
[XML FILE]

So I need to make sure that Policy -> Preferences -> ServerPreferences -> preference -> name = TARGETS exists 
as a preference in ServerPreferences, however, I need to allow other preferences as well but TARGETS must be 
present.


XSD excerpt:

<xs:element name="ServerPreferences">
    <xs:complexType>
        <xs:choice maxOccurs="unbounded">
            <xs:sequence>
                <xs:element name="preference">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="TARGETS"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="value" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:sequence>
                <xs:element name="preference">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name" type="xs:string"/>
                            <xs:element name="value" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:choice>
    </xs:complexType>
</xs:element>


I understand that the CHOICE rule performs an OR, any suggestions?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]