• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Schema help

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to parse a xsd file.

For example, �test.xsd� file:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="note" type="NoteType"/>

<xsd:complexType name="NoteType">
<xsd:sequence>
<xsd:element name="to" type="xsd:string"/>
<xsd:element name="from" type="xsd:string"/>
<xsd:element name="heading" type="xsd:string"/>
<xsd:element name="body" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

And I want to print out basic elements:

Like:
Note
To
From
Heading
Body

How can I do that? Could your provide me with an example?

Thanks in advance,

Gabriel
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since an XSD file is an XML file, you can parse it using SAx or DOM parsers. J2SDK 1.4 has documentation on these or check the faq.javaranch.com

You should be able to use the standard JDK API (1.4? & up) and be able to getAllElementsByTag, then get the attributes for each element node and print what you want (value of the 'name' attribute).

You might want to note that in XML an element 'to' is NOT the same as 'To' or 'from' is NOT the same as 'From' etc...

- m
 
reply
    Bookmark Topic Watch Topic
  • New Topic