How to validate XML files using several XSD?

hi friends i need java code for this application >?
Plz. help me urgent............

Use the parser property
http://apache.org/xml/properties/schema/external-schemaLocation
to specify more than one schemas.
http://xerces.apache.org/xerces2-j/properties.html

Similar Messages

  • Validate XML file using nested XSD's

    Hi,
    I am currently trying to create a method that can validate a XML document based on a long series of nested XSD's.
    I am however not sure of how to implement this validation with the nested XSD's.
    Currently I have created the following function:
         public void validate(InputStream xmlDocument) {
              try {
                   SAXParserFactory spf = SAXParserFactory.newInstance();
                   spf.setNamespaceAware(true);
                   spf.setValidating(true);
                   SAXParser sp = spf.newSAXParser();
                   InputStream schema1 = this.getClass().getResourceAsStream("schema.xsd");
                   InputStream schema2 = this.getClass().getResourceAsStream("schema1.xsd");
                   Object[] schemas = {schema1,schema2};
                   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 JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
                   sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                   sp.setProperty(JAXP_SCHEMA_SOURCE, schemas);
                   sp.parse(xmlDocument, new ParseErrorHandler());
              } catch (SAXException e) {
                   System.out.println(e.toString());
              } catch (ParserConfigurationException e) {
                   System.out.println(e.toString());
              } catch (IOException e) {
                   System.out.println(e.toString());
    The schemas that I reference are imported into the namespace of the class that contains the above method. schema.xsd contains a reference to schema1.xsd.
    The exception that I get is:
    com.sap.engine.lib.xml.parser.NestedSAXParserException: Generic Exception: -> com.sap.engine.lib.xml.util.NestedException: [location : null] ERROR : schema1.xsd (The system cannot find the file specified)
    This I dont understand since the schema1.xsd is located right along with schema.xsd which is found without trouble.
    Hope someone can clearify this issue for me, since I'm somewhat lost.
    Best regards,
    Daniel

    Hi,
    I am currently trying to create a method that can validate a XML document based on a long series of nested XSD's.
    I am however not sure of how to implement this validation with the nested XSD's.
    Currently I have created the following function:
         public void validate(InputStream xmlDocument) {
              try {
                   SAXParserFactory spf = SAXParserFactory.newInstance();
                   spf.setNamespaceAware(true);
                   spf.setValidating(true);
                   SAXParser sp = spf.newSAXParser();
                   InputStream schema1 = this.getClass().getResourceAsStream("schema.xsd");
                   InputStream schema2 = this.getClass().getResourceAsStream("schema1.xsd");
                   Object[] schemas = {schema1,schema2};
                   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 JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
                   sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                   sp.setProperty(JAXP_SCHEMA_SOURCE, schemas);
                   sp.parse(xmlDocument, new ParseErrorHandler());
              } catch (SAXException e) {
                   System.out.println(e.toString());
              } catch (ParserConfigurationException e) {
                   System.out.println(e.toString());
              } catch (IOException e) {
                   System.out.println(e.toString());
    The schemas that I reference are imported into the namespace of the class that contains the above method. schema.xsd contains a reference to schema1.xsd.
    The exception that I get is:
    com.sap.engine.lib.xml.parser.NestedSAXParserException: Generic Exception: -> com.sap.engine.lib.xml.util.NestedException: [location : null] ERROR : schema1.xsd (The system cannot find the file specified)
    This I dont understand since the schema1.xsd is located right along with schema.xsd which is found without trouble.
    Hope someone can clearify this issue for me, since I'm somewhat lost.
    Best regards,
    Daniel

  • How to validate xml file with XSD schema ??  in JDK1.4.2

    How to validate xml file with XSD schema ?? in JDK1.4.2
    i dont want to use new Xerec Jar ...
    Suggest option ...

    Please do not double-post. http://forum.java.sun.com/thread.jspa?threadID=5134447&tstart=0
    Then use Stax (Woodstock) or Saxon.
    - Saish

  • How to access xml file using c

    how to access xml file using c. are there any libraries regarding xml fastinfoset in c? Please let me know about any resources if u know? thanks!!!
    samitha

    There are different methods to access XML data which have pro's and cons. Let us know more about what you want to do and we can help you.

  • How to generate XML file based on XSD in SSIS

    please provide step by step process to create xml based on XSD in SSIS  

    Hi hemasankar,
    In SQL Server Integrated Services, we can generate XML Schema (XSD) file based on a XML file with XML Source Editor. If we want to generate XML file based on a XSD file, we can use Generate Sample XML feature in Visual Studio. For more details, please refer
    to the following steps:
    Click on "XML Schema Explorer" or 'Use the XML Schema Explorer...' to open XML Schema Explorer in Visual Studio. 
    If your Schema file is valid and you are having elements, right-click on element and click on "Generate Sample XML", this functionality generates XML file in temp folder and open ups in the XML Editor.
    The following two document about how to generate XML file based on a XSD file are for your reference:
    http://msdn.microsoft.com/en-us/library/dd489258.aspx
    http://www.codeproject.com/Articles/400016/Generate-Sample-XML-from-XSD
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to update XML file using XSLT

    Hi there,
    I have a "small" issue with exporting data to an XML file using XSLT.
    A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
    Many thanks,
    Ferenc
    P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...

    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
    XSLT approach:  check these online tutorial
    http://www.xml.com/pub/a/2000/08/02/xslt/index.html
    http://www.xml.com/pub/a/2000/06/07/transforming/index.html
    ABAP approach:
    for example you have the xml (original) in a string called say xml_out .
    data: l_xml  type ref to cl_xml_document ,
            node type ref to if_ixml_node  .
    create object l_xml.
    call method l_xml->parse_string
      exporting
        stream = xml_out.
    node = l_xml->find_node(
        name   = 'IDENTITY'
       ROOT   = ROOT
    l_xml->set_attribute(
        name    = 'Name'
        value   = 'Charles'
        node    = node
    (the above example reads the element IDENTITY and sets attribute name/value to the same)
    like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
    so how do I access the XML file in order to update it?
    you have already read this XML into a ABAP variable right?
    Sorry couldnt understand your whole process, why do you need to read local XML file?
    Raja

  • How to read XML file using Automatic ref No

    I need to get the data from the xml file using Automatic reference No.I am a beginner .help me out

    Hi Parthipan,
    An easy way to get started with using XML in LabVIEW is a toolkit called EasyXML -- it's a product from JKI that I helped create
    Thanks,
    -Jim

  • How to validate xml file ?

    I try to validate my xml import file but I can't find proper validation and error message.
    the source where it originates is a system where also texts can be entered manually which are part of the xml file.
    I discoverd myself that & and ! are characters which are not allowed. but I'm looking for a way to check this before I process the xml file.
    I have this coding and I found smum_xml_parse but still the error is not clear about what is wrong ?
    try.
        CALL TRANSFORMATION ('ID')
        SOURCE XML it_xml_import
        RESULT order_header_in = st_sdhd1 order_conditions_in = ta_cond  order_partners = ta_parnr  order_text = ta_sdtext order_items_in = ta_sditm
    CATCH cx_xslt_exception INTO xslt_error.
    xslt_message = xslt_error->get_text( ).
        ASSIGN COMPONENT 'ERROR' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = xslt_message.
    data: gt_temp type STANDARD TABLE OF SMUM_XMLTB.
    itx_xml_import = it_xml_import.
    CALL FUNCTION 'SMUM_XML_PARSE'
      EXPORTING
        xml_input       = itx_xml_import
      tables
        xml_table       = gt_temp
        return          = ta_ret2
    ENDTRY.
    the xslt_message is also very unclear of what is exactly wrong with the file.
    are there any function which can give me more detailed information about the xml file and what is wrong with it ?
    Edited by: A. de Smidt on Feb 1, 2010 10:34 AM

    The ampersand is not allowed in XML CDATA, you must use the entity &amp;amp;

  • How to get XML file using servlets that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • How to generate XML file using select files manually option in MOPz

    Hi Guru's!
    Can someone tell me how can I generate XML file not using the calculate automatically option but using select files manually. thanks!

    Hi Maix,
    You may manually add the files into download basket and then approve it.
    Use the SCN document below for the steps.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10b14f0c-b9af-2e10-ba83-f05ebcfbc3c2?QuickLink=index&…
    Hope this helps.
    Regards,
    Deepak Kori

  • How to generate XML file using EJB ?

    Hi
    Cab anyone point me towards some good examples which creates xml file for the data extracted using EJBs .I have rough idea that this could be done with DOM/JDOm but need some goos example .
    Also I have J2EE RI server,Xalan/Xerces ....Do I need to download DOM/JDOM APIs separately...
    I am relatively new to J2EE .
    Thanks
    Ash

    http://www.theserverside.com/home/index.jsp
    J2EE and XML Development PDF
    Dave

  • How to validate XML using java_xml_pack-summer-02?

    In jaxp1.1, we validate the xml file in this way:
    c:\java -jar Validator.jar myBookStore.xml
    However, in java_xml_pack-summer-02, which is latest version of jaxp, the Validator.jar is not available. So, how to validate xml file?
    Pls help.

    develop your own validator... here is a quick and dirty one, which spits exceptions when error are met:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    public class Validator
      public static void main(String[] args) throws Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        sp.parse(new File(args[0]), new DefaultHandler());
    }

  • Reading XML file using BAPI and then uploading that xml file data into SAP

    I am getting a xml file from Java server. I need to take
    data from this file using BAPI and need to upload into SAP using SAP.
    Please tell me how to read XML files using BAPI's.

    <b>SDIXML_DATA_TO_DOM</b> Convert SAP data (elementary/structured/table types) into DOM (XML
    <b>SDIXML_DOM_TO_XML</b>  Convert DOM (XML) into string of bytes that can be downloaded to PC or application server
    <b>SDIXML_DOM_TO_SCREEN</b> Display DOM (XML)
    <b>SDIXML_DOM_TO_DATA</b>
    data: it_table like t001 occurs 0.
    data: l_dom      TYPE REF TO IF_IXML_ELEMENT,
          m_document TYPE REF TO IF_IXML_DOCUMENT,
          g_ixml     TYPE REF TO IF_IXML,
          w_string   TYPE XSTRING,
          w_size     TYPE I,
          w_result   TYPE I,
          w_line     TYPE STRING,
          it_xml     TYPE DCXMLLINES,
          s_xml      like line of it_xml,
          w_rc       like sy-subrc.
    start-of-selection.
      select * from t001 into table it_table.
    end-of-selection.
    initialize iXML-Framework          ****
      write: / 'initialiazing iXML:'.
      class cl_ixml definition load.
      g_ixml = cl_ixml=>create( ).
      check not g_ixml is initial.
      write: 'ok'.
    create DOM from SAP data           ****
      write: / 'creating iXML doc:'.
      m_document = g_ixml->create_document( ).
      check not m_document is initial.
      write: 'ok'.
      write: / 'converting DATA TO DOM 1:'.
      CALL FUNCTION 'SDIXML_DATA_TO_DOM'
        EXPORTING
          NAME               = 'IT_TABLE'
          DATAOBJECT         = it_table[]
        IMPORTING
          DATA_AS_DOM        = l_dom
        CHANGING
          DOCUMENT           = m_document
        EXCEPTIONS
          ILLEGAL_NAME       = 1
          OTHERS             = 2.
      if sy-subrc = 0.  write  'ok'.
      else.             write: 'Err =', sy-subrc.
      endif.
      check not l_dom is initial.
      write: / 'appending DOM to iXML doc:'.
      w_rc = m_document->append_child( new_child = l_dom ).
      if w_rc is initial.  write  'ok'.
      else.                write: 'Err =', w_rc.
      endif.
    visualize iXML (DOM)               ****
      write: / 'displaying DOM:'.
      CALL FUNCTION 'SDIXML_DOM_TO_SCREEN'
        EXPORTING
          DOCUMENT          = m_document
        EXCEPTIONS
          NO_DOCUMENT       = 1
          OTHERS            = 2.
      if sy-subrc = 0.  write  'ok'.
      else.             write: 'Err =', sy-subrc.
      endif.
    convert DOM to XML doc (table)     ****
      write: / 'converting DOM TO XML:'.
      CALL FUNCTION 'SDIXML_DOM_TO_XML'
        EXPORTING
          DOCUMENT            = m_document
        PRETTY_PRINT        = ' '
        IMPORTING
          XML_AS_STRING       = w_string
          SIZE                = w_size
        TABLES
          XML_AS_TABLE        = it_xml
        EXCEPTIONS
          NO_DOCUMENT         = 1
          OTHERS              = 2.
      if sy-subrc = 0.   write  'ok'.
      else.              write: 'Err =', sy-subrc.
      endif.
      write: / 'XML as string of size:', w_size, / w_string.
      describe table it_xml lines w_result.
      write: / 'XML as table of', w_result, 'lines:'..
      loop at it_xml into s_xml.
        write s_xml.
      endloop.
      write: / 'end of processing'.
    end of code
    Hope this will be useful.
    regards
    vinod

  • How to validate XML against XSD and parse/save in one step using SAXParser?

    How to validate XML against XSD and parse/save in one step using SAXParser?
    I currently have an XML file and XSD. The XML file specifies the location of the XSD. In Java code I create a SAXParser with parameters indicating that it needs to validate the XML. However, SAXParser.parse does not validate the XML, but it does call my handler functions which save the elements/attributes in memory as it is read. On the other hand, XMLReader.parse does validate the XML against the XSD, but does not save the document in memory.
    My code can call XMLReader.parse to validate the XML followed by SAXParser.parse to save the XML document in memory. But this sound inefficient. Besides, while a valid document is being parsed by XMLReader, it can be changed to be invalid and saved, and XMLReader.parse would be looking at the original file and would think that the file is OK, and then SAXParser.parse would parse the document without errors.
    <Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd" name="MyBook">
      <Chapter name="First Chapter"/>
      <Chapter name="Second Chapter">
        <Section number="1"/>
        <Section number="2"/>
      </Chapter>
    </Book>
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Book">
    <xs:complexType>
      <xs:sequence>
       <xs:element name="Chapter" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="Section" minOccurs="0" maxOccurs="unbounded">
           <xs:complexType>
            <xs:attribute name="xnumber"/>
          </xs:complexType>
          </xs:element>
         </xs:sequence>
         <xs:attribute name="name"/>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
      <xs:attribute name="name"/>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    public class SAXXMLParserTest
       public static void main(String[] args)
          try
             SAXParserFactory factory = SAXParserFactory.newInstance();
             factory.setNamespaceAware(true);
             factory.setValidating(true);
             SAXParser parser = factory.newSAXParser();
             parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                "http://www.w3.org/2001/XMLSchema");
             BookHandler handler = new BookHandler();
             XMLReader reader = parser.getXMLReader();
             reader.setErrorHandler(handler);
             parser.parse("xmltest.dat", handler); // does not throw validation error
             Book book = handler.getBook();
             System.out.println(book);
             reader.parse("xmltest.dat"); // throws validation error because of 'xnumber' in the XSD
    public class Book extends Element
       private String name;
       private List<Chapter> chapters = new ArrayList<Chapter>();
       public Book(String name)
          this.name = name;
       public void addChapter(Chapter chapter)
          chapters.add(chapter);
       public String toString()
          StringBuilder builder = new StringBuilder();
          builder.append("<Book name=\"").append(name).append("\">\n");
          for (Chapter chapter: chapters)
             builder.append(chapter.toString());
          builder.append("</Book>\n");
          return builder.toString();
       public static class BookHandler extends DefaultHandler
          private Stack<Element> root = null;
          private Book book = null;
          public void startDocument()
             root = new Stack<Element>();
          public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
             if (qName.equals("Book"))
                String name = attributes.getValue("name");
                root.push(new Book(name));
             else if (qName.equals("Chapter"))
                String name = attributes.getValue("name");
                Chapter child = new Chapter(name);
                ((Book)root.peek()).addChapter(child);
                root.push(child);
             else if (qName.equals("Section"))
                Integer number = Integer.parseInt(attributes.getValue("number"));
                Section child = new Section(number);
                ((Chapter)root.peek()).addSection(child);
                root.push(child);
          public void endElement(String uri, String localName, String qName) throws SAXException
             Element finished = root.pop();
             if (root.size() == 0)
                book = (Book) finished;
          public Book getBook()
             return book;
          public void error(SAXParseException e)
             System.out.println(e.getMessage());
          public void fatalError(SAXParseException e)
             error(e);
          public void warning(SAXParseException e)
             error(e);
    public class Chapter extends Element
       public static class Section extends Element
          private Integer number;
          public Section(Integer number)
             this.number = number;
          public String toString()
             StringBuilder builder = new StringBuilder();
             builder.append("<Section number=\"").append(number).append("\"/>\n");
             return builder.toString();
       private String name;
       private List<Section> sections = null;
       public Chapter(String name)
          this.name = name;
       public void addSection(Section section)
          if (sections == null)
             sections = new ArrayList<Section>();
          sections.add(section);
       public String toString()
          StringBuilder builder = new StringBuilder();
          builder.append("<Chapter name=\"").append(name).append("\">\n");
          if (sections != null)
             for (Section section: sections)
                builder.append(section.toString());
          builder.append("</Chapter>\n");
          return builder.toString();
    }Edited by: sn72 on Oct 28, 2008 1:16 PM

    Have you looked at the XML DB FAQ thread (second post) in this forum? It has some examples for validating XML against schemas.

  • How to validate xml using xsd

    Hi All
    please tell me how to validate xml using xsd
    regards

    Try using this link:
    = http://www.google.nl/search?q=XML+validate+oracle for instance or
    = use the search button on this forum and / or
    = read the FAQ on this (XML DB FAQ
    Thanks Eddie et all, for educating me via http://awads.net/wp/2006/11/14/barts-punishment-for-asking-dumb-questions (don't mind the URL , the info there is really useful)
    The following link on this site is just brilliant: http://www.albinoblacksheep.com/flash/posting.php
    Grz
    Marco
    Message was edited by:
    mgralike

Maybe you are looking for

  • Is there a way of lowering/increasing volume on voice and music

    Is there a way in iMovie 8 to lower/increase voice and or music, like on iMovie HD you could when you were seeing the audio tracks?

  • Accept user input in sql *plus 9.2.0.1.0

    Any body budy can get any idea about my sourcr code? I wrote below code in sql *plus accept p_hire_date1 date FORMAT 'DD-MON-YYYY' prompt 'ENTER hire date from:' accept p_hire_date2 date FORMAT 'DD-MON-YYYY' prompt 'ENTER hire date to:' DECLARE v_hd1

  • Org.omg.CORBA.NO_RESPONSE:   vmcid: 0x0  minor code: 0 completed: Maybe

    Hi, We are using a ejb to connect to corba server (tuxedo) at the backend , in most cases things are fine , but if the server takes more than 65 - 75 secs the above error occurs. The processing at the backend completes just fine .. We are not using n

  • What can u do with motorola h 500 bluetooth

    hi i am very new to this: my qu is i already have a motorola h500 earpiece bluetooth & a macbook. i will be getting an iphone soon. what does the h500 let me do with the macbook? and will it work with the iphone? thanks!

  • Need a good printing app..

    Apparently Google Chrome printing preferences suck. It doesn't allow to print from selection, print black and white or color, things if this nature. Is there an app that will allow me to do these things?