[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Get expected firstchild/siblings
- From: Patrick Lightbody <plightbo@cisco.com>
- To: xml-dev@lists.xml.org
- Date: Sun, 21 Jan 2001 15:33:36 -0800
I'm using the latest (1.2.3) apache XML parser. I have two dummy files (XML
and XSD file) attached below. I'd need to be able to parse through test.xml
and be able to somehow see that the element node "foo" can ONLY (and must)
legally have the element "bar" as it's first child. I'd also like to be
able to see that "bar" can have no child element, and either another "bar"
sibling or no more siblings. Is this possible using any available parser?
It doesn't seem hard, as parser's validator seem to already do such a
thing. XML Spy also has helpers in the program that do such a task.
However, I need to present this in a servlet via an XML parser. So, if
anyone has ideas, please let me know. Thanks.
-Pat
test.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="foo">
<xsd:annotation>
<xsd:documentation>Comment describing your root
element</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="bar" type="xsd:string"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:test.xsd">
<bar>foo</bar>
</foo>