Parse XML Schema in Java

Hi all.
I need to parse an XML Schema and get the following information out of
it:
list of elements allowed in schema
list of attributes for each element - which are required and which
optional
given an element name get elements that it can contain
etc.
Parsing with JDOM XPath seems to be complicated, because there are
many ways to say something in schema, although it would be my
preferred way.
I also looked at JAXB and Xerces, but their APIs seem to be more
complicated than I need.
Is there a simple API for doing what I need?
Thank you very much for help.
Anna

I looked at JAXB, the problem there is that as I understand it, it first converts the schema to a bunch of
Java classes and then I need to compile them and use.
I am looking for something more straightforward, that will allow me to load the schema and do queries, but I can't find anything.
About Xerces - I can't find any good examples for querying schema, all are about validating xml
with given schema, which is not what I need. This is also true about JAXP.
I will be really glad if someone new some good links with examples of Xerces/JAXB used for
querying schema.
Hope that I don't ask for to much.
Thank you very much for help.
Anna

Similar Messages

  • XML Schema for Java Bugs

    I've just downloaded your XML Schema for Java software are have been systematically testing it with a relatively simple document. A few bugs:
    1. the use="required" attribute of the attribute element doesn't have any effect (doesn't show any error message or throw any exceptions) when the required attribute is omitted.
    2. If I declare an element like:
    <element name="age">
    <simpleType>
    <restriction base="positiveInteger">
    <maxInclusive value="100"/>
    </restriction>
    </simpleType>
    </element>
    Then, if I modify my xml document instance to say:
    <age pointless="true">26</age>
    This will throw a non-parser exception with a message of null, instead of saying "Attribute 'pointless' not expected", as it does if I redefine the schema declaration as:
    <element name="age">
    <complexType>
    <simpleContent>
    <extension base="my:ageType"/>
    </simpleContent>
    </complexType>
    </element>
    Will Allan
    null

    I'm glad someone else has noticed that unique keyref and key don't seem to be working with the Dom Parser. If they don't work WHY ARE THEY (key, keyref, unique) IN THE EXAMPLE'S THAT ARE DOWNLOADED WITH THE SCHEMA PARSER. In report.xsd, a file downloaded with the example, it makes clear usage of unique, key, and key ref. But if you violate the schema definitions in the corresponding file report.xml the parser doesn't complain whatsoever. The only time it barfs is if you change the keyref refer attribute to something other than "pNumKey". It obviously has to work. No bone head would send example files along with their product that didn't work.
    So, if anyone at ORACLE or elsewhere has figured out how to use unique, key, or keyref please respond with an explination of how to correctly use them with the parser. Your name will be blessed throughout the ages as a most kind and venerable person. You will be a hallmark, a standard, a shining light for all future generations of what a human being should be! Okay maybe I'm going a little overboard but I'm DESPERATE. With no books or collateral on how this stupid thing works all I can do is hack.
    -Thanks

  • Parse XML in a java stored proc

    I am trying to parse an xml document in a java stored procedure. Just following my nose, I have developed a stored proc that works fine in development (outside the database using JRE 1.4.1) using the Xerces 2.5 parser. But, after having transferred the xerces xercesImpl.jar, xmlapis.jar, and my implementation class into oracle using loadjava when I call my stored proc the code throws an exception trying to build the document with an error like:
    NoClassDef exception org.apache.xerces.jaxp.DocumentFactoryBuilderImpl
    My Code looks like this:
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
    InputStream is = getXMLAsInputStream(xml);
    try {
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse( is );
    ... parse the document ....
    catch (FactoryConfigurationError e) {
    // unable to get a document builder factory
    The exception caught is a FactoryConfigurtionError.
    I'm not particularly attached to xerces, I'm really just looking for a way to parse XML inside my java stored proc, so any help to solve my problem, or an alternative suggestion will be greatly appreciated.
    thanks
    Dale

    I looked again and sure enough the xerces implementation classes were missing. I had run a .cmd file containing these two lines, but it looks like only the first one ran...
    loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xml-apis.jar
    loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xercesImpl.jar
    Now I've got everything working fine with Xerces!
    Dale

  • Problem in parsing XML Schema

    I am trying to parse XML Schema using XSOM. The Schema has <xs:include>s
    e.g. I have first.xsd which includes second.xsd and second.xsd again includes third.xsd.
    First.xsd
    <xs:include schemaLocation="../Second.xsd">....
    Second.xsd
    <xs:include schemaLocation="Third.xsd">....
    When I parse "First.xsd" parser passes the correct path "C:/XSDSchema/Second.xsd"(First.xsd resides in "C:/XSDSchema/Schema/") to the EntityResolver's resolveEntity method. But for Second.xsd it passes "Third.xsd" only (Third.xsd resides in "C:/XSDSchema/" ) .
    Any Idea ?????

    Here is a screenshort of the part of my workflow:
    In the mappings of the "Set Value" activity, I have one line with those properties:
    Location: /process_data/bonusValidationForm/object/data/xdp/datasets/data/BonusValidationForm/buMan agerID
    Expression: /process_data/currentUser/object/@userId
    Where:
    bonusValidationForm is a process variable of my workflow that point my xdp form
    buManagerID is the textfield I want to set
    currentUser is a process variable (type User) that was well setted by the task Find BU Manager

  • Create xml from xml schema in java

    If can i create a xml document framework from xml schema in java, then i can fill the value in java?
    thanks

    An XML document may be created from an XML Schema with JAXB.

  • Parse XML Schema File?

    Dear Sun Developer Network,
    I suppose maybe I should start at the beginning.
    Can anyone outline the first few steps involved in parsing an XML schema file into a traversable data structure in Java?
    I'd like to get a get a discussion started here about this, because I have some questions about the process as I currently understand it, and the more advanced (i'm supposing they're more advanced) questions that I've been asking in the past have gone completely unanswered in this forum. So perhaps, starting from the beginning, and working through to the difficulties I'm encountering would be a better approach to solving those issues.
    Thank you,
    Nels

    >
    Many thanks for your reply! My next question is,
    s, if parsing an XML schema file can be done with a
    SAX or dom parser, then why has Sun bothered to
    develop the JAXB api? What is the difference?
    Hi Nels,
    SAX and DOM are technologies for parsing and JAXB is a technology for databinding. They are 2 different technologies.
    Parsing gives you acess to raw xml
    DataBinding does the parsing and goes one step ahed and loads the data from xml to java objects. It is a higher level of abstraction over parsing
    schema is a specification which helps to define the rules for a valid xml document. It also happens to be xml. DTD is a kind of limited schema which is non xml.
    hope you got the diffrence.
    ps: did you try the -J-Xmx switch with javac to resolve yhe OutOfMemory exception I suggested in your previous post
    Regards,
    Rajagopal

  • How to parse xml data into java component

    hi
    everybody.
    i am new with XML, and i am trying to parse xml data into a java application.
    can anybody guide me how to do it.
    the following is my file.
    //MyLogin.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    class MyLogin extends JFrame implements ActionListener
         JFrame loginframe;
         JLabel labelname;
         JLabel labelpassword;
         JTextField textname;
         JPasswordField textpassword;
         JButton okbutton;
         String name = "";
         FileOutputStream out;
         PrintStream p;
         Date date;
         GregorianCalendar gcal;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public MyLogin()
              loginframe = new JFrame("Login");
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              labelname = new JLabel("User");
              labelpassword = new JLabel("Password");
              textname = new JTextField("",9);
              textpassword = new JPasswordField(5);
              okbutton = new JButton("OK");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labelname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 5;
              gl.setConstraints(textname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 10;
              gl.setConstraints(labelpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 10;
              gl.setConstraints(textpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 15;
              gl.setConstraints(okbutton,gbc);
              Container contentpane = getContentPane();
              loginframe.setContentPane(contentpane);
              contentpane.setLayout(gl);
              contentpane.add(labelname);
              contentpane.add(labelpassword);
              contentpane.add(textname);
              contentpane.add(textpassword);
              contentpane.add(okbutton);
              okbutton.addActionListener(this);
              loginframe.setSize(300,300);
              loginframe.setVisible(true);
         public static void main(String a[])
              new MyLogin();
         public void reset()
              textname.setText("");
              textpassword.setText("");
         public void run()
              try
                   String text = textname.getText();
                   String blank="";
                   if(text.equals(blank))
                      System.out.println("First Enter a UserName");
                   else
                        if(text != blank)
                             date = new Date();
                             gcal = new GregorianCalendar();
                             gcal.setTime(date);
                             out = new FileOutputStream("log.txt",true);
                             p = new PrintStream( out );
                             name = textname.getText();
                             String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
                             p.println(entry);
                             System.out.println("Record Saved");
                             reset();
                             p.close();
              catch (IOException e)
                   System.err.println("Error writing to file");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("OK"))
                   run();
                   //loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    hi, thanks for ur reply.
    i visited that url, i was able to know much about xml.
    so now my requirement is DOM.
    but i dont know how to code in my existing file.
    means i want to know what to link all my textfield to xml file.
    can u please help me out. i am confused.
    waiting for ur reply

  • Writing own getLineNumber for parsing XML Schema

    I'm creating a XML Schema tool that checks that the user is creating valid Schema text.
    What I want to do is if the user has nested an element within a parent that it's not meant to. for example:
    <element name = "1">
            <element name = "2"/>
    </element>I want to return to the user the line number that the problem has occured.
    Because as far as the SAXParser is concerned this is valid XML I can't catch a SAXParseException.
    I'm using DOM to store the XML structure.
    Is there another way I can parse the document so that I can store the line number it orginially came from?
    Many thanks
    Alex

    Thats great, thanks.
    My problem now is how can I access the parent node using SAX().
    I have an arraylist for the parent of valid children, I need to check that the child node is infact one of these nodes.
    The problem being using SAX() I can access the previous node but if their are sibling nodes this will not identify the parent.
    This is the code I have so far:
    public class TestHandler extends DefaultHandler
         int lineNo = 1;
         public void startElement(String namespaceURI, String localname, String rawname, Attributes atts) throws SAXException
              SAX sax = new SAX();
              ArrayList nodes = sax.getSchemaNodes();
              for(int i = 0; i < nodes.size(); i++)
                   SchemaNode sn = (SchemaNode)nodes.get(i);
                   if(sn.getName().equals(localname))
                        System.out.println(sn.getName() + " = " + lineNo);
         public void endElement(String namespaceURI,String localname,String rawname) throws SAXException
         public void characters(char [] buf,int offset,int len)
              lineNo++;
    }Cheers Alex

  • Generate XML Schema from Java classes?

    Hi,
    Considering an XML Mapping, i would like to generate a default XML Schema from my Java class.
    Is there a tool in toplink (10.1.3) to do that or does anyone have an easy way to generate this XML schema?
    Thanks,
    Ludovic

    Hi Ludovic,
    We don't have support for schema generation from Java classes in TopLink 10.1.3. It's required for JAXB 2.0 so it will be available in a future release.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                           

  • How to read xml schema in java?

    hello,
    i need to read the xml schema file,and extract the details like element types.i need to read it not validate it .
    thank you.

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    and set the content handler

  • How do i change xml schema in java

    i want to change a oracle.xml.parser.schema.xmlschema object in java (adding or changing elements, types, etc). is there some hidden way i didn't think of besides changing the xmldocument object behind the schema and rebuilding the schema? i find that rather uncomfortable.
    i'd appreciate any answers, even negative ones :)
    thanks

    Refer to
    http://java.sun.com/webservices/docs/1.1/tutorial/doc/JAXPDOM9.html

  • XML Schema for Java Version 1.0

    Hi everybody,
    1.) in my opinion, the sample schema report.xsd seems to be incorrect with respect to the keyref definition (selector element), but the parser doesn't care anyway. I have modified the report.xml sample to include duplicates of the zip code and invalid keyrefs, but the parser still doesn't care. Despite the notice that unique, key and keyref doesn't work with SAX, it obviously doesn't work at all.
    2.) The "types" contained within the Schema-Definition are not accessible from outside the "oracle" packages, and so far are rather useless. It would be an obvious advantage to access the type- and validation classes of the Schema processor in order to allow for interactive validation of user input, when documents are composed by gathering user input from a http-request. Will this change, as far as XMLSchema is becoming a standard?
    TIA
    Achim

    I'm glad someone else has noticed that unique keyref and key don't seem to be working with the Dom Parser. If they don't work WHY ARE THEY (key, keyref, unique) IN THE EXAMPLE'S THAT ARE DOWNLOADED WITH THE SCHEMA PARSER. In report.xsd, a file downloaded with the example, it makes clear usage of unique, key, and key ref. But if you violate the schema definitions in the corresponding file report.xml the parser doesn't complain whatsoever. The only time it barfs is if you change the keyref refer attribute to something other than "pNumKey". It obviously has to work. No bone head would send example files along with their product that didn't work.
    So, if anyone at ORACLE or elsewhere has figured out how to use unique, key, or keyref please respond with an explination of how to correctly use them with the parser. Your name will be blessed throughout the ages as a most kind and venerable person. You will be a hallmark, a standard, a shining light for all future generations of what a human being should be! Okay maybe I'm going a little overboard but I'm DESPERATE. With no books or collateral on how this stupid thing works all I can do is hack.
    -Thanks

  • Convert ResultSet - Xml with Xml Schema in java

    Hi
    I am using Web Services created in java and will be used from .Net client. Since its a cross platform, so I need to convert the Java ResultSet to XML stream (with schema) so that it could be accesed by .NET client. So I want to know how to convet a Java ResultSet into the desired xml stream (with schema).I know .NET provides this facility through some methods of DATASET.
    Will anybody tell me of any utility, tools or the methods so that I can accomplish this task.
    Thank in advance
    nitin

    I would think that the easiest way to do this would be to use web-services. Get the JWSDP. I don't think there is a direct way to go from ResultSet to XML. You'd have to write or find an external tool, though Oracle can create XML straight from the database.

  • How to handle multiple xmls(schemas) using java

    Can anyone give me solution for the below issue.
    We are handling five types of xmls(five different xsds) in our application.We have the XML and its XSD in database. Currently we are using JAXB to create and update the xmls.
    In future there is a chance to add new schema. In that case our current code will not work (because the JAXB is tightly coupled with the xsds) for new schema. Is there any technology or method to handle this situvation?
    I am looking for early respons.
    Thanks
    Dhans

    You have no idea? Then look in your JavaMail download and you will find several sample programs that you can use to get started. It would also help to read the JavaMail FAQ (Google will find it easily for you).

  • Error in XML Parsing  through Schema doc.

    I know this is not the correct group for XML related queries. I had posted the query in XML forum but could not get any reply. I have been in the forum and know this is very active forum.
    Please help if you can..
    Hi Friends,
    I am trying to validate XML file as per the defined schema document through JAXB parser.
    Following is my xml. schema and java class code.
    XML File*
    <?xml version="1.0"?>
    <notify xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NotificationDetailsSchema.xsd">
    <notification>
    <alertname>Alert1</alertname>
    <deletable>Y</deletable>
    <descurl>Alert1URL</descurl>
    </notification>
    <notification>
    <alertname>Alert2</alertname>
    <deletable>Y</deletable>
    <descurl>Alert2URL</descurl>
    </notification>
    </notify>
    Schema file_
    <?xml version="1.0" encoding="windows-1252"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:element name="notify">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="notification" maxOccurs="unbounded">
    <xsd:complexType mixed="true">
    <xsd:sequence>
    <xsd:element name="alertname">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="deletable">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="Y|N"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="descurl">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    Java Class_
    SAXSource source = new SAXSource (xmlInputSource);
    SchemaFactory sf = SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaFileObj);
    Validator validator = schema.newValidator ();
    validator.setErrorHandler (new ParserErrorHandler());
    validator.validate (source);
    I tried to execute the validation through stand along java class and it worked correctly.
    However when I added this class into my Fusion web application, I am getting following error.
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Alert1'._
    Can you please help me to figure out this problem?
    Edited by: Jaykishan on Jul 20, 2011 10:04 AM

    earlier it was
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'USAVER'.anmd now it is
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Alert1'.some problem in this Alert1 message is what i guess.. some parsing error.. look closely..
    i guess some of the xml characters are not rendered properly in forum software.. or it may be truncated.. so i believe something wrong which is not visible..

Maybe you are looking for

  • Coding in Update Rules accessing a Z-Table

    Hi, I have a datarecord that looks as follows: 0MATERIAL:                     1000 ZMC (Manufacturing Company)      03 ZFAC (Facility ID)               16 ZSHIP (Total Shipments)         500 Units <b>There is a Z-Table in R/3 (ZPLANT) that maps ZMC a

  • Attaching search help to SCREEN FIELDS AND TABLE FIELDS

    Hello experts, Himanshu here. Could you please explain how we can assign search Help to a screen field AND TABLE FIELDS in ABAP? Please reply at the earliest,as we have some deliverables to be met Thanks

  • Upgrading from 10.3.9 to Tiger onto iMacG4 (flat panel)

    Ok, heres the issue. When attempting to solve some minor software issues with a co-workers compy, (mail and safari would bounce once and fail to operate) i chose the Archive and Install option from OSX 10.4.X and what not. Her old version was OSX.3.9

  • A606 - how to add a language easily?

    a606_s034_141203_row v13 2014/11/184.4.2 Bought this very neat mobile in Dubai for my son, but unluckily no German language available in settings.Would like to avoid any deep operations on it because my skills are limited in that. Has anyone here got

  • 64 bit version of Ultranav driver not available for download

    Using either Update Retriever or System Update, version 7.202.1616.206 of the ThinkPad UltraNav Driver 2 (Alps) 64 bit is missing from the System Update catalogue. Package ID: 6EGY02WW is not presented. Only the 32 bit version (Package ID: 6EGX02WW)