Java code to access XML (with unknown SCHEMA)

Dear participants,
My name is Raghavendra , i have a requirement of reading XML files Dynamically and parse them and create java types for manipulation . i will not be provided with sxd files (no schema compilation )coz no one knows how many types of structures are there. i want a generic solution. Please Help.
Thanks ,
Raghavendra Ach
you can mail me to " [email protected]"

JAXB has been available as an early release download for some time. There are also XML Binding packages available from Borland (JBuilder) and Castor. These tools create Java classes from a source document, xml,dtd etc. You can use these classes to marshal-unmarshal XML documents.
Dave

Similar Messages

  • Hi I need this asap... "Java code to generate XML File from XML Schema"

    Hi all....
    I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...
    PS: I already posted in the afternoon... this is the second posting.

    take look at :
    http://sourceforge.net/projects/jaxme/
    this might help...

  • Java code to generate XML File from XML Schema

    Hi I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...

    JAXB has been available as an early release download for some time. There are also XML Binding packages available from Borland (JBuilder) and Castor. These tools create Java classes from a source document, xml,dtd etc. You can use these classes to marshal-unmarshal XML documents.
    Dave

  • 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);

  • How to validate an xml with a schema w/o specifying the schema in the xml

    I have done xml validation with xml schemas, where the xml points to the xsd to use. However, I would like to not have to specifiy the xml schema in the xml document (and can't ensure that the xml coming to us has that in it). How do I, in the java code, tell it what schema to use in validation?
    Brian

    static final String schemaSource = argv[0];
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

  • Java code to convert XML file to ISO XML format

    Hi Experts,
    I need to convert an XML file to ISO Xml format using Java code.I dont have any idea about the ISO XML format.I searched but what i am getting is ISO is an encoding in XML.
    It will be very helpful if any one can give me a sample ISO XML file, and any way around to carry out the required conversion.
    Thanks .
    Anika

    Hi,
    For ISO encoding you need the XML file to be converted with below providing the encoding paramter as ISO. for e.g.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    instead of
    <?xml version="1.0" encoding="UTF-8"?>
    this can be possible with using XML encoders.
    Refer XML encoding--> http://www.w3schools.com/XML/xml_encoding.asp
    Refer Java Code with uasage of XMLEncoder
    http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html
    Thanks
    Swarup

  • Sample java code which reads xml attributes using DOM Parser

    Hi Friends,
    I am looking for a sample java code which uses the DOM Parser to read the attributes values.
    My xml looks like below
    <?xml version='1.0' encoding='UTF-8'?>
    <root>
    <header unid="100" status="true">
    <validation stage="1" processed="10"/>
    </header>
    </root>
    Experts please help...
    Thanks in Advance
    JJ

    You have probably found lots of resources on the www for this by now, if not: [http://www.w3schools.com/dom/default.asp|http://www.w3schools.com/dom/default.asp]

  • 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">

  • Validate xml with complextype schema without root element!

    Hi All!
    I have a problem that. I want to validate a xml data of complextype but the schema i want to validate is[b] not have root element.
    For example:
    The schema like that
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:complexType name="Name">
              <xs:sequence>
                   <xs:element name="FirstName" type="xs:string"/>
                   <xs:element name="LastName" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>
    and the xml data i want to validate like this
    <?xml version="1.0" encoding="UTF-8"?>
    <Name xmlns="www.thachpn.test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <FirstName>Pham</FirstName>
         <LastName>Thach</LastName>
    </Name>
    My Algorithm is like that:
    I create a complextype object by above schema
    then i create new element with given name and namespace
    after that i use schema of this element to validate xml data.
    I use xmlparserv2 lib of oracle
    But i can not find how to create complextype from schema or create element with have complextype.
    Please help me.
    Thanks a lot!

    <?xml version="1.0" encoding="UTF-8"?>
    Modify the schema.
    Add a root element.
    <xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:element name="Name" type="Name"/>
    <xs:complexType name="Name">
    <xs:sequence>
    <xs:element name="FirstName" type="xs:string"/>
    <xs:element name="LastName" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>

  • Handling XMLs with unknown structures.

    Hello Experts,
       I have to build a generic interface RFC -> PI -> JMS, which will receive XML structure as a string in import parameter of RFC.
    Then I need to convert this string to XML, add digital signatures and then output the signed payload to JMS Queues.
    I have been looking at SDN posts and found that XSLT can be used to convert string to XML. But the catch is I am not aware of the XML structures that will be sent in as a string. So how can I handle these unknown structures? Or what should be the structure of the target Interface for XSLT mapping??
    Any inputs on this will be of great help.
    Kind Regards,
    PIQueries_2010

    If you dont want the target structure to be validated XSLT/java mapping is the way to go as pointed out by MIchal.
    If you use the new feature, I believe it will validate the target structure.
    @Michal,
    Just a quick clarification, when we use java/xslt mapping to skip target message validation in PI 7.1 is it mandatory to have the operation name exactly same as Service Interface name? I recently ran into an issue where the Service interface name was different from the operation name and the Java mapping was giving an error saying "Unable to validate root element" or something similar (Ofcourse, the content was binary file and hence java mapping to skip the target structure validation).
    Thanks
    Jai

  • Get a table from XML with unknown number of columns

    Guys, I'm looking if it is possible to get the following result:
    imagine I have an XML like one of the following (it doesn't matter which one, I just give a few examples for you to have a choice). The main idea, that there are described several columns and values for 1 row of these columns, e.g.:
    SQL> with t as (select
      2  ' <column>
      3    <name>col1</name>
      4    <value>100</value>
      5   </column>
      6   <column>
      7    <name>col2</name>
      8    <value>200</value>
      9   </column>' xml from dual union all
    10             select
    11  ' <column>col1
    12     <value>100</value>
    13    </column>
    14    <column>col1
    15     <value>100</value>
    16    </column>' from dual union all
    17             select
    18  '<col1>100</col1>
    19  <col2>200</col2>' from dual)
    20             --
    21             select * from t
    22  /
    XML
    <column>
      <name>col1</name>
      <value>100</value>
    </column>
    <column>
      <name>col2</name>
      <value>200</value>
    </column>
    <column>col1
       <value>100</value>
      </column>
      <column>col1
       <value>100</value>
      </column>
    <col1>100</col1>
    <col2>200</col2>
    SQL> I want to get the following result from this XML:
          COL1       COL2
           100        200So the main idea here is that the number of columns can vary - it is not fixed.
    So it is quite similar to dynamic SQL.
    Is it possibe with XML?

    The only general way to get a flexible amount of columns I know of is to use table functions returning anydataset.
    It should be rather straightforward to pass in a xml document and return its tablestructure respectivly (though the »structure« of the xml must be fixed).
    Would that be an acceptable way of doing this?

  • Java code to access the SLD

    Hi,
    I'm writing a java application that needs to connect to the SLD Server and then query and return data about the SID and available instances and associated database(s).
    I have figured out the connection piece using  SAP_JCODestinationAccessor, but have not figured out how to get the SID and instance names.  It appears that the methods I want to use are in the lcrclient.jar file (perhaps SAP_ApplicationSystemInstance?
    Are there any code example or javadocs that are available to help me understand the methods that are available for data retrieval from the SLD?
    Thanks in advance,
    Tammy

    Hi,
    Yes, the examples are where I got my start from.  In general my problem is that I didn't have an JCO's defined, so no data was being returned. Thus the example only helped me minimally.
    I'm assuming that when not using a JCO, I still can make a connection to the SLD Server and then using the CIM objects be able to retreive the SID and associated instances.
    Tammy
    Tammy

  • Read XML with different schema definitions

    Hello,
    I have an XML stored in a table as XMLTYPE and I have no problem to read the first part (ELMAHeader)
    WITH t AS(
    SELECT XMLTYPE(
    q'[<?xml version = '1.0' encoding = 'UTF-8'?>
    <ELMAKM xsi:noNamespaceSchemaLocation="./KM/01.00/ELMAKM_000001.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:km="http://www.zivit.de/KiStA/KiStAM/V1.0/KiStA-KiStAM-Anfrage">
       <ELMAKOM>
          <ELMAHeader ELMAKMVersion="1">
             <AuthSteuernummer>BG</AuthSteuernummer>
             <AccountID>11</AccountID>
             <KundeneigeneID>1</KundeneigeneID>
             <Verarbeitungslauf>PROD</Verarbeitungslauf>
             <ErstellungsDatum>2014-09-16</ErstellungsDatum>
             <ErstellungsZeit>11:00:27.7</ErstellungsZeit>
          </ELMAHeader>
          <ELMAVerfahren>
             <KISTA_KM_ANTW UUID="0345" OrdBegriff="SLD"
             xsi:schemaLocation="http://www.zivit.de/KiStA/KM/01.00-r000001 ./KM/01.00/ELMAKM_KISTA_000001.xsd"
             xmlns="http://www.zivit.de/KiStA/KM/01.00-r000001"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:k="http://www.zivit.de/KiStA/Std/01.00-r000001">
                <KiStAV_DL Zulassungsnummer="2"/>
                <KiStAV Zulassungsnummer="2" Name="SLD"/>
                <Antwort xsi:type="AntwortArt3" UUID="0f" KdOrdBegriff="4">
                   <ReturnCode>1</ReturnCode>
                   <Anlass Datum="2014-08-11" Grund="1"/>
                   <PersAngabe>
                      <Person>
                         <k:NName>B</k:NName>
                         <k:VName>Y</k:VName>
                         <k:GebDt>1944-10-11</k:GebDt>
                      </Person>
                      <Adresse xsi:type="k:InlandsAdresse">
                         <k:Str>A-Str.</k:Str>
                         <k:HausNr>5</k:HausNr>
                         <k:Ort>M</k:Ort>
                         <k:Plz>8</k:Plz>
                      </Adresse>
                   </PersAngabe>
                </Antwort>
             </KISTA_KM_ANTW>
          </ELMAVerfahren>
       </ELMAKOM>
    </ELMAKM>]') x FROM dual
    SELECT  x
           ,elma.ELMAKMVersion
           ,elma.AuthSteuernummer
           ,elma.AccountID
           ,elma.KundeneigeneID
    FROM    t
           ,XMLTABLE(
                '/ELMAKM/ELMAKOM/ELMAHeader'
                PASSING t.x
                COLUMNS ELMAKMVersion       VARCHAR2(8)     PATH '@ELMAKMVersion'
                       ,AuthSteuernummer    VARCHAR2(10)    PATH 'AuthSteuernummer'
                       ,AccountID           VARCHAR2(10)    PATH 'AccountID'
                       ,KundeneigeneID      VARCHAR2(10)    PATH 'KundeneigeneID'
                ) elma
    But how can I read the second part(ELMAVerfahren)? I tried many selects but I get no results, e.g.
    WITH ...
    SELECT  x
           ,elma.UUID
    FROM    t
           ,XMLTABLE(
                XMLNAMESPACES(
                    DEFAULT './KM/01.00/ELMAKM_KISTA_000001.xsd'
                    ,'http://www.zivit.de/KiStA/KiStAM/V1.0/KiStA-KiStAM-Anfrage' AS "km"
                    ,'http://www.zivit.de/KiStA/Std/01.00-r000001' AS "k"
                '/ELMAKM/ELMAKOM/ELMAVerfahren/KISTA_KM_ANTW'
                PASSING t.x
                COLUMNS UUID       VARCHAR2(8)     PATH '@UUID'
                ) elma
    DB version
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    Regards
    Marcus

    Hi Marcus,
    If you declare a default namespace using the XMLNamespaces clause, it'll apply to all unqualified elements referenced by the XQuery expression.
    In your attempt, ELMAKM, ELMAKOM and ELMAVerfahren are treated as being part of the default namespace, which is wrong since those nodes are in no namespace.
    To handle this kind of situations, where there are default namespace redefinitions down the tree, you have to declare a prefix :
    SELECT  x 
           ,elma.UUID 
    FROM    t 
           ,XMLTABLE(
               XMLNamespaces('http://www.zivit.de/KiStA/KM/01.00-r000001' as "ns0") 
            ,  '/ELMAKM/ELMAKOM/ELMAVerfahren/ns0:KISTA_KM_ANTW' 
                PASSING t.x 
                COLUMNS UUID       VARCHAR2(8)     PATH '@UUID' 
                ) elma

  • 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.

  • Problem parsing XML with schema when extracted from a jar file

    I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
    I get the following exception:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
    This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
    I have output the retrieved XML to a file and compared it with my original source and they are identical.
    I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
    Any suggestions?
    The code is as follows:
      public void open(File input) throws IOException, CSLXMLException {
        InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
          builder = factory.newDocumentBuilder();
          builder.setErrorHandler(new CSLXMLParseHandler());
        } catch (Exception builderException) {
          throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
        Document document = null;
        try {
          document = builder.parse(input);
        } catch (SAXException parseException) {
          throw new CSLXMLException(parseException.toString());
        }

    I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
    Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.

Maybe you are looking for

  • May 2007 Screenshots

    Guidelines · DO NOT post full resolution screenshots!  You can use the "mogrify" command (pacman -S imagemagick) to make a thumbnail of your screenshot: $ cp screenie.png thumb-screenie.png $ mogrify -resize 20% thumb-screenie.png Twenty percent of t

  • Other solutions requested: CP1210 Series Cartridge Alaignment in Windows 8.1

    Hello, Adding to the original post (copied below), I'm also using Windows 8.1 on my knew computer, and seems to have the same problem. I tried the solutions you suggested, but the problem percist.   The printed colors are offset.  The black color is

  • Ipod touch 2G: All App crash

    This just happened couple days ago when I noticed that all my apps crash. The only apps that doesn't crash are the App store, mail, music, safari...etc. But the other app such as games crash right away when I click on it. The only way I can solve the

  • Opening files in Word and Excel - blank or nothing at all

    Hi all, I am a newbie to Mac (going on my third week) and am having problems with MS Office documents and spreadsheets. Most of the time opening a .doc from Finder will result in a "cloud" but Word does not open. The same with Excel. Sometimes Word o

  • Form background

    Hey guys, I created a form in DW and added a background image via the page properties window. I can view it just fine in the design window, however, in preview, the background is missing. Is there an extra step to putting a background behind a form,