Validating parser with SAX and SCHEMA

Hi,
Can I validate a xml file by SCHEMA with Sun's SAX?
If i can, what versions i need?
jsdk1.3 and SAX 1.0 are enought ?
What is JAXP , it's a SAX version ?
Thanks.
Sorry for my english !

I tried this doc with the file source, but it does't work, i have the error message following :
java.lang.IllegalArgumentException: No attributes are implemented
Download the latest copy of JAXP from http://java.sun.com
ERROR! INVALID FILE
But I have JAXP installed with JavaTM XML Pack, and I didn't change the source, juste copy on my hard disk and run the .java.
Why do I have this errors ? please.

Similar Messages

  • Changing xmlschema while parsing with sax

    Hello world,
    I`m using the sax-parser (xerces) and i want to combine different schema-files to parse an xml-String;
    <root>
         <intervall>1,5</intervall>
         <nix>jetzt echt nix!</nix>
         <testtag>
              <text>huhu joe</text>
         </testtag>
         <theLast>das letzte element</theLast>
    </root>e.g. i want to parse the tag testtag with another schema ??
    does anyone have an idea or a sample coding ??
    thank you very much

    thank you for the reply, but i want to change the Schema file while parsing the xmlString with Sax, without manipulation the xmlString;
    the xml-String i get is fixed;
    wish you all a great sunday

  • Problems parsing & with SAX

    Hello all,
    I'm new to SAX and facing quite odd problem with it while parsing data.
    If the data to be parsed has &amps, SAX cuts out everything before it. For example;
    <url>www.foobar.com?something=123&blaa=456</url>
    This will return:
    blaa=456
    Any ideas what's wrong or should I post some sample code ?

    You didn't post the code that has this problem, but I think I know what is happening.
    You are probably assuming that the characters() method will always return you the entire text node all at once. This is not the case. You should write code like this:
    1. startElement: create a new StringBuffer.
    2. characters: append the data to that StringBuffer.
    3. endElement: now you have all the data in the StringBuffer and you can use it.

  • Xerces Validation Issues with Honour All schema Locations

    Way back in 2009/2010 there was a bug - 284272 - that was never updated with Xerces information about validation. We have a similar issue in Luna and Mars with the WTP validation framework (with Xerxes at the center) and I'm wondering if it's due to Xerces 2.9 or something else.
    I'm not a savvy XSD guy, but the issues detailed in 284272 still occur for us with certain schema combinations. We're encountering it specifically with the JBoss/SwitchYard project and the SCA schemas we extend for the SwitchYard runtime.
    The following error is displayed in the Problems tab:
    cvc-complex-type.2.4.a: Invalid content was found starting with element 'sca:interface.java'. One of '{"http://docs.oasis-open.org/ns/opencsa/sca/200912":documentation, "http://docs.oasis-open.org/ns/opencsa/sca/200912":interface, "http://docs.oasis-open.org/ns/opencsa/sca/200912":binding, "http://docs.oasis-open.org/ns/opencsa/sca/200912":callback, "http://docs.oasis-open.org/ns/opencsa/sca/200912":requires, "http://docs.oasis-open.org/ns/opencsa/sca/200912":policySetAttachment, "http://docs.oasis-open.org/ns/opencsa/sca/200912":extensions}' is expected. switchyard.xml src/main/resources/META-INF line 7 XML Problem
    Can someone revisit 284272 and let me know if this is indeed a Xerxes issue under the covers with the example included in the bug? It's not our example, but has the same general problem.
    I just don't want to open a duplicate of 284272 without knowing more about how the Honour All Schema Locations stuff works under the covers and if it is indeed caused by Xerces - indeed if it might be fixed by an update to Xerces further down the line (they're up to 2.11 and there was a 2.9.1 it looks like we might be able to more simply move to if it's fixed there).
    Thanks all!
    --Fitz

    I think this is the odata4 that you need for 7.3
    SCA
    ODATACXFEXT11_0-10012140.SCA
    SP11 for SAP ODATA4J+CXF-REST LIB 7.30
    0
    Info
    10352
    26.02.2014
    This might be the only package you need; it might be in your best interest to avoid manually downloading files and rely upon Solution Manager's MOpz feature to query your IdM system and let it track down all the needed packages.

  • How to Parse XML with SAX and Retrieving the Information?

    Hiya!
    I have written this code in one of my classes:
    /**Parse XML File**/
              SAXParserFactory factory = SAXParserFactory.newInstance();
              GameContentHandler gameCH = new GameContentHandler();
              try
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse(recentFiles[0], gameCH);
              catch(javax.xml.parsers.ParserConfigurationException e)
                   e.printStackTrace();
              catch(java.io.IOException e)
                   e.printStackTrace();
              catch(org.xml.sax.SAXException e)
                   e.printStackTrace();
              /**Parse XML File**/
              games = gameCH.getGames();And here is the content handler:
    import java.util.ArrayList;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    class GameContentHandler extends DefaultHandler
         private ArrayList<Game> games = new ArrayList<Game>();
         public void startDocument()
              System.out.println("Start document.");
         public void endDocument()
              System.out.println("End document.");
         public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
         public void characters(char[] ch, int start, int length) throws SAXException
              /**for (int i = start; i < start+length; i++)
                   System.out.print(ch);
         public ArrayList<Game> getGames()
              return games;
    }And here is the xml i am trying to parse:<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <Database>
         <Name></Name>
         <Description></Description>
         <CurrentGameID></CurrentGameID>
         <Game>
              <gameID></gameID>
              <name></name>
              <publisher></publisher>
              <platform></platform>
              <type></type>
              <subtype></subtype>
              <genre></genre>
              <serial></serial>
              <prodReg></prodReg>
              <expantionFor></expantionFor>
              <relYear></relYear>
              <expantion></expantion>
              <picPath></picPath>
              <notes></notes>
              <discType></discType>
              <owner></owner>
              <location></location>
              <borrower></borrower>
              <numDiscs></numDiscs>
              <discSize></discSize>
              <locFrom></locFrom>
              <locTo></locTo>
              <onLoan></onLoan>
              <borrowed></borrowed>
              <manual></manual>
              <update></update>
              <mods></mods>
              <guide></guide>
              <walkthrough></walkthrough>
              <cheats></cheats>
              <savegame></savegame>
              <completed></completed>
         </Game>
    </Database>I have been trying for ages and just can't get the content handler class to extract a gameID and instantiate a Game to add to my ArrayList! How do I extract the information from my file?
    I have tried so many things in the startElement() method that I can't actually remember what I've tried and what I haven't! If you need to know, the Game class instantiates with asnew Game(int gameID)and the rest of the variables are public.
    Please help someone...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    OK, how's this?
    public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
              current = "";
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
              try
                   if(qualifiedName.equals("Game") || qualifiedName.equals("Database"))
                        {return;}
                   else if(qualifiedName.equals("gameID"))
                        {games.add(new Game(Integer.parseInt(current)));}
                   else if(qualifiedName.equals("name"))
                        {games.get(games.size()-1).name = current;}
                   else if(qualifiedName.equals("publisher"))
                        {games.get(games.size()-1).publisher = current;}
                   etc...
                   else
                        {System.out.println("ERROR - Qualified Name found in xml that does not exist as databse field: " + qualifiedName);}
              catch (Exception e) {} //Ignore
         public void characters(char[] ch, int start, int length) throws SAXException
              current += new String(ch, start, length);
         }

  • Xerces2_6_2 validating with dtd and schema.. please help

    Hi I am having trouble validating an xml document using xerces2_6_2
    I have a DTD that containes only entity references, and a schema that is used to ensure the xml is valid.
    I get this error.
    Element type "my root tag" must be declared!
    It seems to expect all validation grammer to be in the dtd. I have sucessfully validated with xml spy and oxygen,(oxygen uses xerces too).
    This is a real pain I really would lie to take advantage of using schemas, I know I could just use entity references in this form and not have a dtd but this is really not acceptable.
    I have tried out all the xerces specific properties and features but this has not worked either.
    Perhaps I should implement a validator? Does anyone have any ideas?
    thanks

    My solution, I thought to take, wasn't the right way, but I have found following thread within the forum
    http://forum.java.sun.com/thread.jspa?forumID=34&threadID=527461
    The problem you have described points to a dtd error. Considering the thread above, it would make sense. It is a presumption, but perhaps that is because of the new Xerces version. I would try with an older one.
    Sorry, that I could help you along.

  • Generating XML content with SAX including schema reference

    Hi all, XML newbie question here.
    I'm trying to generate an XML document from a certain file format using SAX, but I can't figure out how to get the generated XML document to include a schema reference.
    Here's the code, it's taken from posts on this forum, so it should be familiar:
    StreamResult streamResult = new StreamResult(out);
            SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try {
                TransformerHandler hd = tf.newTransformerHandler();
                Transformer serializer = hd.getTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                hd.setResult(streamResult);
                hd.startDocument();
                AttributesImpl atts = new AttributesImpl();
                hd.startElement("http://maul.ddm.apm.bpm.eds.com", "DTR_XML", "DTR_XML", atts);
                hd.endElement("http://maul.ddm.apm.bpm.eds.com", "DTR_XML", "DTR_XML");
                hd.endDocument();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (TransformerConfigurationException e) {
                e.printStackTrace();
            }Here's the output I get:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <DTR_XML/>
    And I'm looking for output like this (I think - basically I have this dtr_xml.xsd located at the root web directory on http://maul.ddm.apm.bpm.eds.com and I want the generated XML file to reference that schema for validation when parsing):
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <DTR_XML xmlns="http://maul.ddm.apm.bpm.eds.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd"/>

    Yes, you've led me along the right track with the attributes stuff. Here's what I've got right now...
    StreamResult streamResult = new StreamResult(out);
            SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try {
                TransformerHandler hd = tf.newTransformerHandler();
                Transformer serializer = hd.getTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                hd.setResult(streamResult);
                hd.startDocument();
                AttributesImpl atts = new AttributesImpl();
                atts.addAttribute("", "xmlns", "xmlns", "CDATA", "http://maul.ddm.apm.bpm.eds.com");
                atts.addAttribute("", "xsi", "xmlns:xsi", "CDATA", "http://www.w3.org/2001/XMLSchema-instance");
                atts.addAttribute("", "schemaLocation", "xsi:schemaLocation", "CDATA", "http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd");
                hd.startElement("", "DTR_XML", "DTR_XML", atts);
                hd.endElement("", "DTR_XML", "DTR_XML");
                hd.endDocument();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (TransformerConfigurationException e) {
                e.printStackTrace();
            }This produces the output I wanted earlier...
    As for the org.xml.sax.helpers.NamespaceSupport, I can't seem to find any documentation on using it anywhere, and the javadoc is cryptic to me. Maybe it's used internally in SAX for tracking namespaces or something like that.
    Another interesting thing to me is that if I use the code you gave:
    atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation",
         "xsi:schemaLocation", "CDATA", "http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd");I don't see "http://www.w3.org/2001/XMLSchema-instance" anywhere in the output. Is SAX ignoring the namespace uri argument? It appears so. The javadoc states that the uri argument is "The Namespace URI, or the empty string if none is available or Namespace processing is not being performed." It would appear that Namespace processing is not being done... but I don't know how to turn it on.

  • Problem with JDOM and schemas

    I'm trying to parse (and validate) an XML document with JDOM.
    My root element is declared in the schaema whixh is asociated to the document.
    But during parsing, an exception saying that my root element is not declared is thrown.
    Can someone axplain to me what can happen ?
    Thank's

    What's this element ?
    My schema is indicated by the xsi:schemeLocation attribute of my root-element .

  • Validating attributes with a non-schema namespace

    Hey,
    Just wondering if anyone could possibly help me with the following.
    Under 3.3.2 (http://www.w3.org/TR/xmlschema-1/#declare-element) it says that the definition of "element" can have "any attributes with non-schema namespace" .
    If I have a schema (a.xsd) and import another schema (b.xsd):
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                       xmlns:b="http://www.foo.com"
                       elementFormDefault="qualified"
                       attributeFormDefault="unqualified">
         <xs:import namespace="http://www.foo.com"; schemaLocation="b.xsd"/>
        <xs:element name="someName" b:validAttribute="invalidValue"/>
    </xs:schema>Is there a way to ensure that b:validAttribute is validated when I use SchemaFactory#newSchema(StreamSource)?
    I've been hunting around and it just seems to ignore it / always let it pass regardless of the value.
    The w3 XMLSchema.xsd uses processContents="lax" for the xs:anyAttribute, so as I understand it, it should be validated it if it finds b.xsd (which it does)?
    As a side note, it also allows b:invalidAttribute="foo" which I'd also like to catch..
    Any help would be much appreciated!
    Cheers,
    Meph.

    If you take your schema and validate it against the schema for schemas from the W3C site then I am sure the 'b:validAttribute' will be validated.
    But I have no idea whether the SchemaFactory will process schemas that way (i.e. by validating them against the schema for schemas).

  • XML - 0112 Error on parsing using SAX and xml file in InputSource object.

    I need to parse a XML string and extract some information. I have to use SAX parser. I'm converting hte string to InputSource and then trying to parese.
    i'm getting XML-0112 error, my guess is that it is not able to locate DTD file but i tried hardcoding the whole path in DOCTYPE tag.
    i tried doing setSystemId also but no luck.
    null

    Can you post a simple test case to look at?

  • High parsing with Siebel and Oracle RAC 10gR2

    Hi all,
    I'm working for a company that uses Siebel 8 with a 2 nodes RAC 10gR2. 70GB SGA with assured minimum values for shared pool 16GB, 50GB db buffer cache and the rest distributed among the other pools.
    In the last weeks we are facing a very annoying issue in our production system, at random times we have a very high concurrency peak with contention events like:
    - cursor: pin S wait on X
    - latch: library cache
    and a performance problem as a consequence.
    I have read all the documents on metalink about these types of waiting events and how to troubleshoot it, but I can't get rid of this problem.
    We have dynamic SGA configured, but we haven't had any resizes in the last weeks.
    We didn't have many "version count" for query, we are about <40.
    In the AWR I have noticed that we have very high parsing (in most cases query execute=query parse). We have talked to our Siebel support team to propose them the use of CURSOR_SHARING=FORCE, but they told us that it's unsupported.
    We have increased the parameter session_cached_cursors from 50 to 1000, but in the last days the problem has even got worse.
    I suppose that the solution could be reducing the parse count and elapsed parse time, but without changing the CURSOR_SHARING parameter and not much help from Siebel support, I don't know how to achieve this.
    Does anyone have any idea?

    The only way you can reduce the number of parses is to fix Siebel (in other words - not much you can do).

  • How to  HTMLEditorKit's parser with Sax Parser?

    How does one do it? I know you need to override getParser method. But the ParserCallback's handleStartTag, handleEndTag etc expect a parameter pos of type int. Needless to say, the pos is undocumented. I have not idea what value to pass. If I pass -1, I get some exceptions. Anyone has a working code snippet which he/she can share?
    Thanks a bunch
    Narayanan

    ParserCallback is like an event listener.
    Take for example a MouseListener. You don't invoke the mouseClicked(...) method. You add code to the mouseClicked(...) method to respond to the mouseClicked event.
    Same thing with the ParserCallback. You don't invoke the handleStartTag(...) method. As the ParserCallback is parsing an HTML Document it will notify you when it finds a start tag in the Document. It tells you the tag it found and the position of the tag in the Document.
    Here is a simple example that just displays all the text in the document:
    import java.io.*;
    import java.net.*;
    import javax.swing.text.html.parser.*;
    import javax.swing.text.html.*;
    public class ParserCallbackText extends HTMLEditorKit.ParserCallback
         public void handleText(char[] data, int pos)
              System.out.println( data );
         public static void main(String[] args)
              throws Exception
              Reader reader = getReader(args[0]);
              ParserCallbackText parser = new ParserCallbackText();
              new ParserDelegator().parse(reader, parser, true);
         static Reader getReader(String uri)
              throws IOException
              // Retrieve from Internet.
              if (uri.startsWith("http:"))
                   URLConnection conn = new URL(uri).openConnection();
                   return new InputStreamReader(conn.getInputStream());
              // Retrieve from file.
              else
                   return new FileReader(uri);
    }

  • Xml parsing with Java

    Hi ..!
    I am having a small problem friends if anybody of you can just help me resolving this .
    I am quiet new to working with parsing XML with SAX and Dom java parsers .
    Problem is when we want to extract the Element name ,Attribute Name or Attribute Value it is quiet simple in Java to do so .
    But supposing i want to extract the value between the tags of an element how can we do so either their is a simple method that i have missed or their is a tedious procedure that i am ignorant of.
    eg- <Node1> this is my name <Node1>
    Java source output -this is my name.
    Thanx to you people for co-operating
    Take care
    Akshat

    in SAX u can do like this
         boolean nodeflag=false;
         public void startElement(String uri,String localName, String qName,Attributes attributes)throws SAXException
              if(qName.equals("Node1"))
                   nodeflag=true;
         public void endElement (String uri, String localName, String qName)throws SAXException
              if(qName.equals("Node1"))
                   nodeflag=false;
         public void characters(char[] ch, int start,int length)throws SAXException
              String s=new String(ch,start,length);
              if(nodeflag==true)
                   if(!s.trim().equals(""))
                        System.out.println(s.trim());
         }here in characters method u can work with data

  • Are enterprise admin and schema admin rights required after installation?

    Hi,
    Exchange 2010 has been installed in our organisation a few years ago, and is running fine. Exchange was installed with an account with enterprise and schema admin rights. I have just found out that this account still has those rights, I think that this isn't
    necessary, and is in fact een security risk. I think that membership of Exchange Organization Administrators and Organization Management plus domain admin rights is enough. Am I right or does this account really need enterprise and schema admin rights?

    Yes you are correct. You will need schema admin rights when installing service packs though.

  • Oracle XML parser and schema validation

    Hi Forum,
    I have problem parsing XML with validation against XML schema. I define location of schema (URL) in xml file and Oracle parser could not find the schema (xml file is correct - checked in other programs). When I point to xml schema directly from Java (using parser.setXMLSchema) before calling parser.parse, it works just fine. Where is the problem? Does oracle parser works correctly with XML Schema?
    TIA,
    Alex

    SAXParser saxParser=new SAXParser();
    saxParser.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    Specify a Schema to validate a XML document with, for the SAXParser.
    saxParser.setXMLSchema(SchemaUrl);
    DefaultHandler handler=new DefaultHandler();
    saxParser.setErrorHandler(handler);
    Parse the XML document to validate with the XML schema.
    saxParser.parse(XmlDocumentUrl);

Maybe you are looking for