Validating xml doc using schema

I was wondering if you can the following validation of an xml document using schema:
<parent>
    <child>Jogn</child>
    <child>Hanna</child>
    <child>Blake</child>
    <childCount>3</childCount>
<parent>the childcountValue equals the number of child node. is this possible using
schema or do do i have to use an application to do this?
thanx in advance

thanx dvohra, but i already know how to validate schema using a parser.
I'm looking for a way in the schema that specified thhat the total number of child elemnt equals to the integer value of the childTotal element. I don't even know if this is possible. If possible, what (tag) would i use. i don't need answer..hint would be nice.
my other solution is to write an application that use a SAX parser to parse the xml doc. Although this is relatively easy, i would like to keep the validation within on file (the schema)..rather than have it be in the schema and a ContentHandler.

Similar Messages

  • How to structure an XML doc using schema?

    Hi there,
    I have an XML file with a grouped <employee> tags like,
    <employee>
    <employeename>John</employeename>
    <employeename>Dave</employeename>
    </employee>
    I want to structure above xml file to be like this
    <employee>
    <employeename>John</employeename>
    </employee>
    <employee>
    <employeename>Dave</employeename>
    </employee>
    Can I do that in a XML schema (.xsd file)? If I can, how do I do that?
    Thanks,
    Chandi

    Hi Dave,
    Thanks for your response.
    I create this XML from .xsd files using a tool (MapForce by Altova which allows me to do the mappings between relational database table columns and elements in the .xsd file, and it creates Java code for me), the data is read from a database to compose this XML file.
    Everything works fine with this XML file, I just want to change the structure of the XML file when it composes it, I was wondering if I could do that by changing the existing .xsd file?
    Its not easy to use XSLT, I�m dealing with over 600 hierarchical elements with over 15 .xsd files.
    So, what are my options?
    All I want to know is, what should I change in the .xsd in order to compose this XML in the structure that I want.
    It groups all the employee names (<employeename> tag) under one <employee> tag, instead I want to have individual <employee> tags for each and every <employeename> tags (<employee> tag around <employeename> tag for each and every employee)
    Is it possible at all?
    Thanks,
    Chandi

  • Does XDB supports validating xml against multiple schemas?

    The XMLType has some methods for validating an xml documents against a schema, e.g., SCHEMAVALIDATE, etc.. does XDB support validating xml against multiple schemas (Just like what JAXP or Xerces have done)? Or what's the current situation about this issue? thanks.

    did you try using the import schema element instead of the include elemnt?

  • Issue in Store XML into Schema generated tables and Validation XML against registered schema.

    Hello friends,
    I am facing some problem when store xml into generated tables from registered schema.
    This is my Schema
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abc.inf.in/test" targetNamespace="http://www.abc.inf.in/test" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="abc.xsd"/>
      <xs:element name="project" type="student">
      <xs:annotation>
      <xs:documentation> This is a Documentation</xs:documentation>
      </xs:annotation>
      </xs:element>
    </xs:schema>
    -- This is my xml document
    <project versao="2.00" xmlns="http://www.abc.inf.in/test">
      <test xmlns="http://www.abc.inf.in/test">
      <intest version="2.00" Id="testabc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  >
      <ide>
      <cUF>35</cUF>
      <cNF>59386422</cNF>
      <natOp>this is post</natOp>
      <indPag>1</indPag>
      <mod>55</mod>
      <serie>1</serie>
      </ide>............
    Not giving full because it's too long.
    1. I Successfully registered Schema into database
    2. Then i generate table from registered Schema
    2. In my java code i validated XML document against Schema and it's successfully validate.
    3. But when i stored this XML into this generated table it's give me error
       Like :
    INSERT INTO XMLTABLE
    VALUES
    (XMLTYPE(bfilename('MYDIR','testabc.xml'),NLS_CHARSET_ID('AL32UTF8')))
    Error report:
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    And i have to store this xml into this tables so what i have to do ?

    Thanks for your reply odie_63.
    I got this my error solution. My XML document is not well structured based on my registered XML Schema.
    Means In My XML Document there are some invalid value and that not match my schema pattern so it's gives this error
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    For Solution we have two ways
    1. I have changed this literal "94032000" value in my xml file then save it.
    2.
    - We have to delete this schema then
    - we have to change Schema pattern for particular element
    like :--
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve"/>
      <xs:pattern value="[0-9]{3}"/>
    </xs:restriction>
    - then store xml into database it works..
    Thanks.

  • Error while Validating xml against a schema using jaxp

    Hi All,
    Following code validates xml against a schema using JAXP .It gives SAXNotRecognizedException error when you run the program.
    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    SAXParserFactory myFactory = SAXParserFactory.newInstance();
    myFactory.setNamespaceAware(true);
    myFactory.setValidating(true);
    javax.xml.parsers.SAXParser parser;
    String filename = "C:/Note.xml";
    File xmlFile = new File(filename);
    try
         DefaultHandler handler = new DefaultHandler();
         parser = myFactory.newSAXParser();
         parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
         parser.parse(xmlFile, handler);
    catch (ParserConfigurationException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (SAXException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (IOException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    Error Details :
    org.xml.sax.SAXNotRecognizedException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
         at org.apache.xerces.framework.XMLParser.setProperty(XMLParser.java:1682)
         at org.apache.xerces.parsers.SAXParser.setProperty(SAXParser.java:770)
         at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
    How do i fix the above mentioned problem ?
    Thanks in Advance.
    Ansh

    Validate with the JAXP DOMParser instead of the JAXP SAXParser.
    To validate with a SAXParser use the xerces SAXParser.
    thanks,
    Deepak

  • Compare 2 XML Docs using JAXB

    Hello List,
    I use JAXB for parsing and generating XML docs. It works well after some time to learn to use it.
    But now I want compare 2 xml docs.
    I think the equal function is the right way, but I can't find any implementation from this function in the generated classes.
    Do I look right? Is it possible to compare xml docs with JAXB?
    Any other hints.
    regards Dietmar

    Earlier this year, I needed such a tool and finally wrote one after not being able to find one. It was a lot of work. It compared two DOM documents.
    In our case, we were testing a new server implementation to create XML result files from requests from our client. I connected to a new server and an old server and sent the identical input to both. I then validated the two results using DTD's (which is all we had) and then did a brute force comparison of the two Document objects.
    To make things more difficult, there were some known differences. The new version returned a few new tags and attributes in certain cases. I had to avoid using these as a reason to declare a mismatch. Also, there were timestamps and URLs returned in the files I was processing, so I had to ignore these tags as well.
    Another thing to consider is that attributes do not have to be presented in any sequence, so I had to compare in a non-order-specific way. I built two HashMaps, and first looked up each old attribute in the HashMap for new attributes. If I found a match, I removed this attribute from BOTH HashMaps, when I got to the end, anything lef t over in either HashMap was an orphan.
    It was a lot of work, and my solution is probably not usable outside of its environment, and I don't have permission to release the source anyway.
    Dave Patterson

  • Need help on processing XML doc using Java store procedure

    I am currently working on project to read, parse XML document and store data in XML document into database columns. I use JAVA API-OracleXMLSave in my java store procedure to do it, which use URL of XML doc to read, parse doc and store the data to database columns. My java store procedure works fine when XML doc is saved in server, but got "ORA-29532: Java call terminated by uncaught Java exception:
    oracle.xml.sql.OracleXMLSQLException: No such file or directory" if XML doc is in client's PC instead of in server. I think the problem comes from the URL that created using OracleXMLSave
    --createURL(fileName) based on the filename. what will be the filename if XML document located in Client PC like C:\myprojects\xmldoc.xml?
    Thank you in advance if anyone can give some hints.

    I am currently working on project to read, parse XML document and store data in XML document into database columns. I use JAVA API-OracleXMLSave in my java store procedure to do it, which use URL of XML doc to read, parse doc and store the data to database columns. My java store procedure works fine when XML doc is saved in server, but got "ORA-29532: Java call terminated by uncaught Java exception:
    oracle.xml.sql.OracleXMLSQLException: No such file or directory" if XML doc is in client's PC instead of in server. I think the problem comes from the URL that created using OracleXMLSave
    --createURL(fileName) based on the filename. what will be the filename if XML document located in Client PC like C:\myprojects\xmldoc.xml?
    Thank you in advance if anyone can give some hints.

  • Conversion of xml doc using xsl

    hai,
    i have a following xml document.i have to write a xsl template which only the content
    between the <FUSIONHUB_MESSAGE> AND </FUSIONHUB_MESSAGE> TAGS.
    CAN ANY BODY GIVE THE TEMPLATE FOR ME ?
    I HAVE WRITTEN A TEMPLATE WHICH IS NOT WORKING PROPERLY.
    HERE IS THE XML DOC:
    <?xml version="1.0"?>
    <FUSIONHUB>
    <FUSIONHUB_INFO>
    <FUSIONHUB_COMPANY_ID>s0001 </FUSIONHUB_COMPANY_ID>
    <FUSIONHUB_REC_COMPANY_ID>r0001</FUSIONHUB_REC_COMPANY_ID>
    <FUSIONHUB_MESSAGE_CATEGORY_CODE>m1</FUSIONHUB_MESSAGE_CATEGORY_CODE>
    </FUSIONHUB_INFO>
    <FUSIONHUB_MESSAGE>
    <SALESORDER>
    <ROW num="1">
    <S_ORDER_NO>o19001</S_ORDER_NO>
    <CLIENT_NO>c00001</CLIENT_NO>
    </ROW>
    <ROW num="2">
    <S_ORDER_NO>o19002</S_ORDER_NO>
    <CLIENT_NO>c00002</CLIENT_NO>
    </ROW>
    </SALESORDER>
    </FUSIONHUB_MESSAGE>
    </FUSIONHUB>
    i just want the output like this:
    <FUSIONHUB_MESSAGE>
    <SALESORDER>
    <ROW num="1">
    <S_ORDER_NO>o19001</S_ORDER_NO>
    <CLIENT_NO>c00001</CLIENT_NO>
    </ROW>
    <ROW num="2">
    <S_ORDER_NO>o19002</S_ORDER_NO>
    <CLIENT_NO>c00002</CLIENT_NO>
    </ROW>
    </SALESORDER>
    </FUSIONHUB_MESSAGE>
    null

    I think your question is wrong.
    XML parser is supposed to check for well-formness of a document, meaning make sure all the tags are open/closed properly. Optionally a parser can perform validations on a document based on its DTD. If there is no DTD available there is no validations required.
    null

  • Error while printing generated XML doc using DBMS_OUTPUT

    while generating XML document using XDK for PL/SQL i am getting " ORU-10027: buffer overflow, limit of 1000000 bytes " error even though i had set DBMS_OUTPUT to 1000000.
    Is there any way to getrid of this problem .
    i am using this code ..
    CREATE OR REPLACE procedure SQLToXML1 is
    queryCtx DBMS_XMLquery.ctxType;
    result CLOB;
    begin
    DBMS_OUTPUT.ENABLE (1000000);
    queryCtx := DBMS_XMLQuery.newContext ('select * from depolib_library' )
    result := DBMS_XMLQuery.getXML(queryCtx);
    printClobOut(result);
    DBMS_XMLQuery.closeContext(queryCtx);
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end;
    urgent help is needed
    Thanks
    null

    No, It is a PO Print only. Only for changes to PO that do not affect the value of the PO,this error occurs. When i select the entry for the PO and click on Output message, the output message fails. On clicking Display Message, it shows the message - No schedules exist for the Scheduling Agreement XXXXXX(the PO number".
    So,it is not for Scheduling Agreements but for PO only. I know it is weird to see such an error on the PO output message in ME9F.
    Pls help.

  • Validating xml input against schema's registered in database

    Hi,
    We have an application that stores a massive XSD document (with cyclical references between schemas) in a VARCHAR2 column of a table. The XSD is loaded everytime an xml input needs to be parsed. The problem is that the XSD is very huge, and maintaining it is going to be a problem as it continues to grow. I don't beleieve this is the most efficient way of doing this.
    What I would like to do is to register each of the schemas that are part of the large XSD and use the <include schemaLocation/> directive. I have seen tutorials for doing this. Example tutorial at this link:
    http://www.cs.utah.edu/classes/cs5530/oracle/doc/B10501_01/appdev.920/a96620/xdb05obj.htm
    My sole purpose for registering the XSD's is to validate any xml input that is passed in as input to my Java program that is running in the database; I don't want to store the input xml in a table. If the input is successfully validated, my program will continue processing.
    I have seen some Java OTN tutorials which have methods with 2 parameters - xml, and xsd. I want to avoid this approach because in my case, the XSD would already be registered in the database.
    Any tips would be very much appreciated.
    Cheers,
    Rudi

    AN XML Document may be validated with schema registered in database.
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb08tra.htm#sthref843

  • Error validating xml with xsd schema on JSDK 1.4

    Hi All,
    Asked to me do it a Web Service client in Java and validate its xml answer with an xsd file using 1.4 plataform.
    I googled and I saw many samples to 1.5 plataform, and few samples to 1.4, but anyway I tried to do what they asked to me.
    I got connect with service, got the response and so I went to validate that xml with an xsd file.
    But I got an error on that task. The error occurs in the following line
    "Schema schema = factory.getSchema();"
    Bellow my code
    final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
              final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
              final String schemaSource = "C:\\GetAuthorizationServiceOutput.xsd";
              final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();          
              factory.setNamespaceAware(true);
              factory.setValidating(true);
              try {
              factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
              factory.setAttribute(JAXP_SCHEMA_SOURCE,new File(source));
              catch (IllegalArgumentException x) {
                   System.out.println(x.getMessage());
    DocumentBuilder builder = null;
              Document document = null;
              try {
                   builder = factory.newDocumentBuilder();
                   document = builder.parse(new InputSource(new StringReader(ret.toString())));
              } catch (ParserConfigurationException e) {
                   e.printStackTrace();
              } catch (SAXException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
              **Schema schema = factory.getSchema();**
              Validator validator = schema.newValidator();
              try {
                   validator.validate(new DOMSource(document));
              } catch (SAXException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
    and here is the exception :
    Caused by: java.lang.NoSuchMethodError: javax.xml.parsers.DocumentBuilderFactory.getSchema()Ljavax/xml/validation/Schema;
    Method onLinkClicked of interface wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = btBack, page = br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails, path = 30:form:btBack.RelationsDetails$4, isVisible = true, isVersioned = true]] threw an exception
    wicket.WicketRuntimeException: Method onLinkClicked of interface wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = btBack, page = br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails, path = 30:form:btBack.RelationsDetails$4, isVisible = true, isVersioned = true]] threw an exception
         at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:198)
         at wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74)
         at wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65)
         at wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEvents(AbstractCompoundRequestCycleProcessor.java:57)
         at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:896)
         at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:929)
         at wicket.RequestCycle.step(RequestCycle.java:1010)
         at wicket.RequestCycle.steps(RequestCycle.java:1084)
         at wicket.RequestCycle.request(RequestCycle.java:454)
         at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:219)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
         at java.lang.Thread.run(Thread.java:534)
    Caused by: java.lang.reflect.InvocationTargetException
         at sun.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:187)
         ... 39 more
    Caused by: java.lang.NoSuchMethodError: javax.xml.parsers.DocumentBuilderFactory.getSchema()Ljavax/xml/validation/Schema;
         at br.com.weev.finan.mkb_er.business.manager.impl.RelationManagerImpl.getAuthorizationService(RelationManagerImpl.java:152)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
         at $Proxy22.getAuthorizationService(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:377)
         at wicket.proxy.$Proxy39.getAuthorizationService(Unknown Source)
         at br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails$4.onClick(RelationsDetails.java:125)
         at wicket.markup.html.link.Link.onLinkClicked(Link.java:254)
         ... 43 more
    It's my first time doing that, so I'm confuse to do it.
    Thank you
    Juliano.

    This is how.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    dbfac.setNamespaceAware(true);
    SchemaFactory factory1 = SchemaFactory
                        .newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory1.newSchema(new File("person.xsd"));
    dbfac.setSchema(schema);
    DocumentBuilder dbparser1 = dbfac.newDocumentBuilder();
    Document doc1 = dbparser1.parse(new File("person.xml"));
    Validator validator1 = schema.newValidator();
    DOMSource dm1 = new DOMSource(doc1);
    DOMResult domresult1 = new DOMResult();
    validator1.validate(dm1, domresult1);

  • Urgent!! - Validating Any Element using schema

    Hi,
    I am relatively new to XML. I need to return the out in XML. Here is the sample schema
    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   targetNamespace="http://www.its.ws/Inventory"
         xmlns="http://www.its.ws/Inventory">
         <xsd:element name="RESULT">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="DESCRIPTION"/>
                        <xsd:any minOccurs="0"/>
                   </xsd:sequence>
                   <xsd:attribute name="Status" use="required" type="xsd:integer"/>
                   <xsd:attribute name="ErrorCode" use="required" type="xsd:integer"/>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="DESCRIPTION" type="xsd:string"/>
         <xsd:element name="DELIVERY">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="po_del_date"/>
                        <xsd:element ref="po_del_qty"/>
                   </xsd:sequence>
         </xsd:complexType>
         </xsd:element>
         <xsd:element name="po_del_date" type="xsd:string" />
         <xsd:element name="po_del_qty" type="xsd:string"/>
    </xsd:schema>
    And here is my XML
    <?xml version="1.0"?>
    <Result xmlns="http://www.its.ws/Inventry"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.its.ws/Inventry Inventry.xsd"
              Status="1" ErrorCode="12">
              <Description>Vendor Code is NULL</Description>
              <Delivery>
                        <PurchaseOrderDelDate>2002-09-24</PurchaseOrderDelDate>
                        <PurchaseOrderDelQty>100.00</PurchaseOrderDelQty>
              </Delivery>
    </Result>
    In my XML file,
    I may or may not have Delivery element.
    If allows to have delivery element, doesn't validated it.
    When i validated in XMLWriter, it validates the Delivery element.
    Is this a bug in Oracle XML Engine or i am missing anything.
    Thanks in advance for ur advice

    Sorry, thats not the correct xml file.
    <?xml version="1.0"?>
    <RESULT xsi:schemaLocation="http://www.its.ws/Inventory ResultAny.xsd"
              xmlns="http://www.its.ws/Inventory"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              STATUS="0"
              ERRORCODE="0">
         <DESCRIPTION>There is no description defined</DESCRIPTION>
         <DELIVERY>
                        <!--<po_del_date>asdf</po_del_date>
                        <po_del_qty>asdf</po_del_qty>
                        -->
         </DELIVERY>
    </RESULT>
    Above is sample XML file. I am not concentrating on namespace, schema file and location ect,
    I have commented po_del_date & po_del_qty. There present is mandatory. It just checks whether xml file is proper or not, it does not validate, DELIVERY elements childs.
    When i validate it in XMLWriter, which users MSXML 4.x, it validates.

  • Creating XML Doc using JDOM... HELP!!!!!

    I've got a constructor which creates an Annotation object ... each object has 4 fields;
    Annotation Owner
    Date/time submitted
    ID
    Annotation Text
    When each Annotation object is constructed it is placed on a Vector array.
    I now want to create an XML Document for the Annotation object on the Vector Array...
    I am using JDOM and have managed to create a simple constructor:
    // Class XMLDocument...
    // This class is a subclass of MooNotes 2 that is designed to construct a XMLDocument containing a particular
    // Annotations details...
    class XMLDocument {
         long docID;
         org.jdom.Document xmldoc;
         * <p>
         * Build a simple XML document in memory
         * </p>
         // Constructor for the XMLDocument class...
         // This constructor will construct an
    // XMLDocument and populate the data fields with the particular
         // Annotation contents.
         // The constructor is passed a DOCUMENT ID and a JDOM document when invoked and it uses this data to construct
         // the XML Document.
         public XMLDocument(long docID, org.jdom.Document xmldoc) {
         this.docID = docID;
         this.xmldoc = xmldoc;
         xmldoc.setDocType(new org.jdom.DocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"));
         org.jdom.DocType docType = xmldoc.getDocType();
         messagearea.append("XMLDocument Element: " + docType.getElementName() + " \n");
         messagearea.append("XMLDocument Public ID: " + docType.getPublicID() + " \n");
         messagearea.append("XMLDocument SystemID: " + docType.getSystemID() + " \n");
         messagearea.append("Document successfully built " + " \n");
    How do I construct a Document to accept and hold the contents of an Annotation Object?
    P.S.
    AnnotationSubmitter is a String
    So is Date/time
    ID is a long number
    Annotation Text is also a String

    Since your constructor receives a org.jdom.Document already, it's difficult to figure out what you're trying to do. I'm also not sure what you mean by a Vector array, but I'm gonna give it a shot. To construct a simple org.jdom.Document (without namespace) I would do the following:
    Element root=new Element("ALL_ANNOTATIONS");
    Document=new Document(root);
    doc.setDocType(new DocType(  ...[your stuff]... ));
    and loop through your annotations objects
    for(int i=0;i<n;++i)
        root.addChild(new Element("ANNOTATION")
                      .addChild(new Element("ANNOTATION_OWNER")
                            .setText(annotObjects.getAnnotationOwner()))
    .addChild(new Element("ANNOTATION_TIME")
    .setText(......getTime()))
    .addChild(new Element("ANNOTATION_ID")
    .setText(""+annotObjects[i].getID()))
    .addChild(new Element("ANNOTATION_TEXT")
    .setText(......getText()));
    In the end this should give you the equivalent of:
    <ALL_ANNOTATIONS>
    <ANNOTATION>
    <ANNOTATION_OWNER>
    Text of First Annotation Owner
    </ANNOTATION_OWNER>
    <ANNOTATION_TIME>
    Time/Date of annotation
    </ANNOTATION_TIME>
    <ANNOTATION_ID>
    1234567
    </ANNOTATION_ID>
    <ANNOTATION_TEXT>
    Some Annotation Text
    </ANNOTATION_TEXT>
    </ANNOTATION>
    <ANNOTATION>
    etc. N-1 Times.
    </ANNOTATION>
    </ALL_ANNOTATIONS>
    Hope that helps.

  • JDOMException thrown validating XML against a schema with Xerces2

    I'm trying to validate a document with JDOM and Xerces 2.
    I can validate it with XMLSpy (it works, my document is valid).
    But with JDOM and xerces, this error occurs when parsing and validating my document:
    org.jdom.JDOMException: Error on line 6 of document file:///E:/developpement/SitePerso/xml/xml/listeEntreprises.xml: cvc-complex-type.2.4.a: Invalid content starting with element 'item'. The content must match '(("":nom){0-1},("":item){0-UNBOUNDED})'.
    My XML document:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XML Spy v4.3 U (http://www.xmlspy.com) by de Boussineau (none) -->
    <!--Sample XML file generated by XML Spy v4.3 U (http://www.xmlspy.com)-->
    <liste xmlns="E:/developpement/SitePerso/xml/domain~1/schemaListe" ... E:\developpement\SitePerso\xml\schemas\schemaListe.xsd">
    <item xsi:type="xsel:typeEntreprise">
    <xsel:nom>PHOENIX I.S.I.</xsel:nom>
    <xsel:groupe>Taffioles</xsel:groupe>
    <xsel:adresse>2 rue du centre</xsel:adresse>
    The element <nom> before <item> is not required. So what's the problem ?

    ...

  • Validating xml with external schema

    Hi,
    I want to validate a xml against an external schema using java and the xml WILL NOT contain any reference to the schema. Any help in the matter is most welcome.
    A typical example of such an xml is given below:
    <Envelope >
    <Body>
    " Some content here"
    </Body>
    </Envelope>
    I used the following code but it did not validate the xml.It simply parsed.
    public class TestParser {
         public static void main(String[] args) {
              final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
              final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
              try {
                   SAXParserFactory saxpfactory = SAXParserFactory.newInstance();
                   saxpfactory.setNamespaceAware(true);//
                   saxpfactory.setValidating(true);//
                   SAXParser parser = saxpfactory.newSAXParser();
                   parser.setProperty(JAXP_SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");//
                   parser.setProperty(JAXP_SCHEMA_SOURCE, "http://www.w3.org/2001/06/soap-envelope");//
                   parser.parse(new File("C:\\TEMP\\request.xml"), new DefaultHandler());
              } catch (FileNotFoundException fileNotFoundException) {
                   fileNotFoundException.printStackTrace();
              } catch (IOException ioException) {
                   ioException.printStackTrace();
              } catch (SAXException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (ParserConfigurationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              System.out.println("exiting main ");
    Regards

    In the schema root element xs:schema add namespace declaration.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    In the XML document root element add xmlns:xsi and xsi:noNamespaceSchemaLocation attributes.
    <root_element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://c:/testing.xsd">

Maybe you are looking for

  • How can I change the installation path  of JWS?

    I have to install the JRE 1.4.0_01 in silent mode on Windows XP. For the JRE I can set the installation path in the corresponding dialog and record it in an *.iss file. When starting the silent installation the JRE is correctly installed into this pa

  • Enable / disable combo box in datagrid cell

    I have a datagrid with 8 columns 2 check boxes a text box and 5 combo boxes. I am trying to disable the combo boxes if the first check box is not checked. So far I am able to disable the entire column with the combo box in it, but what i am trying to

  • Problem in date format

    There is one date characteristic in my query , which has same format with infoobject 0DATE(yyyymmdd)...When I am executing the report that date field is displayed as mm/dd/yyyy , but in the dataprovider the same date field has been displayed as dd/mm

  • 5D mark ii workflow in FCPX (proxy editing?)

    I am hoping for some advice about workflow using a 5D mark ii and FCPX I have just made the jump from FCP7 to FCPX and I am about to start editing 1.5TB of 5D H.264 footage and an old macbook pro. As far as I understand the recommended workflow would

  • Why does the battery need to be recharged so often?

    My iPod is brand new and need recharging every other day. Why and how does this happen?