Best way to validate and xml file against a schema?

As the subject states, I want to validate my xml file against a given schema....
Currently my code looks like this:
InputSource ipSource = new InputSource(new ByteArrayInputStream(bytesData)); // my xml file
DOMParser parser = new DOMParser();
parser.parse(ipSource);
Document doc = parser.getDocument();
I see that there is a setFeature method on DomParser.... but from what I read that doesnt support
xml schema's, just DTD's. So what is the best way to validate with schema's?
Any help would be appreciated

This is the other way I tried doing it.... the problem with this way is I am building my xml file through DOM
operations... and I haven't figured out how to add the schema line to the xml file through DOM manipulations.
Has anyone done this bofore?
try
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     factory.setNamespaceAware(false);
     factory.setValidating(true);
     InputSource ipSource = new InputSource(new ByteArrayInputStream(bytesData));
     DocumentBuilder builder = factory.newDocumentBuilder();
     doc      = builder.parse(ipSource);
     return doc;
catch(Throwable t)
     System.out.println("parse error: " +t);
return doc;
}

Similar Messages

  • Validate a XML file against multiple schema files

    Hello everybody!
    How can I validate a XML file against multiple schema files?
    I have the following XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <bulkCmConfigDataFile xmlns:es="SpecificAttributes.3.0.xsd"
                             xmlns:xn="genericNrm.xsd"
    xmlns="configData.xsd">
    <fileHeader fileFormatVersion="32.615 V4.2" vendorName=""/>
    <configData dnPrefix="Undefined">
    <xn:SubNetwork id="3G">
    <xn:SubNetwork id="RNC01">
    <xn:MeContext id="RNC01">
    <xn:VsDataContainer id="RNC01">
    <xn:attributes>
    <xn:vsDataType>vsDataMeContext</xn:vsDataType>
    <xn:vsDataFormatVersion>SpecificAttributes.3.0</xn:vsDataFormatVersion>
    <es:vsDataMeContext>
    <es:userLabel>RNC01</es:userLabel>
    <es:ipAddress>172.21.3.17</es:ipAddress>
    <es:neMIMversion>vF.5.0</es:neMIMversion>
    </es:vsDataMeContext>
                                  </xn:attributes>
    </xn:VsDataContainer>
    </xn:MeContext>
    </xn:SubNetwork>
    </xn:SubNetwork>
    </configData>
    <fileFooter dateTime="2006-11-24T11:56:07Z"/>
    </bulkCmConfigDataFile>
    I want to load this file into a table, validate it (against SpecificAttributes.3.0.xsd, genericNrm.xsd and configData.xsd) and query that table. How would the INSERT .. and the SELECT ... for userLabel attribute look like?
    Many thanks!

    Hi Peter,
    Please use the validateXML BPEL Property : This property validates incoming and outgoing XML documents. If set to true, the Oracle BPEL Process Manager applies schema validation for incoming and outgoing XML documents. This property is applicable to both durable and transient processes. The default value is false.
    Cheers
    A

  • How to use Xerces to validate an XML file against a DTD

    Hi, can anybody tell me how to use Xerces to validate an XML file against a DTD. its urgent. post some sample code. it would be helpful for my project. isupposed to use SAX parser(Xerces)
    Thanx in advance

    Come on, I googled "xerces validate" and the first link is the Xerces FAQ:
    http://xerces.apache.org/xerces-j/faq-general.html
    And of course "how to validate" is a Xerces FAQ. Help yourself by doing a little research instead of waiting for other people.

  • What is the best way to include an xml file in JSP?

    I have a jsp page that I need to include an xml file. The xml file
              uses an xsl to render the file. What is the best way to include the
              xml file and still maintain the structure of the style sheet?
              Thanks
              Jennifer
              

              The best way is using the tag lib. If you cannot, but you can use JAXP, you can
              try
              javax.xml.transform.Transformer.transform(Source xmlSource,
              Result outputTarget)
              throws TransformerException
              You construct the transformer with you xsl, use you xml file or DOM to form xmlSource,
              and use JSPWriter "out" to form outputTarget (StreamResult). But if your JSP page
              generates the xml itself, tag lib is the only way.
              [email protected] (Jennifer) wrote:
              >[email protected] (Jennifer) wrote in message news:<[email protected]>...
              >> I have a jsp page that I need to include an xml file. The xml file
              >> uses an xsl to render the file. What is the best way to include the
              >> xml file and still maintain the structure of the style sheet?
              >>
              >> Thanks
              >>
              >> Jennifer
              >
              >Or is there a way to parse the xml file with the jsp page to display
              >the information. I cannot use the Java Standard Tag Libraries as the
              >version of iplanet we are running does not support the JSTL
              >
              >Thanks
              >
              >Jennifer
              

  • How to validate an XML file with XSD Schema on JDK 1.4

    Hi
    I'm looking for samples how to validate xml files with xsd schema using jsdk 1.4
    Thank you.

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

  • Best way to find and copy files

    If i have a list of 2000 file names and want to find:
    if they exist in folder x
    then copy to folder y
    else
    output an error messege to txt file.
    What would the most efficient way to do this be? So far i've used listFiles() and put a >HUGE< directory listing into an Array. Then I did a comparison for each file name in the list against the array. I know this cant be the most efficient way. I posted earlier in the board but for some reason NO one answered. Can anyone suggest and easier way to do this? and what is the best way to copy files in java? opening a bufferwriter etc? Essectially, im doing a restore from multiple backup directories to the original directory. Please help me if you can take the time.
    Thank you,
    jon

    If i have a list of 2000 file names and want to
    find:
    if they exist in folder x
    then copy to folder y
    else
    output an error messege to txt file.
    What would the most efficient way to do this be?In a loop just read and write each file. If it does not exist, print an error.
    So far i've used listFiles() and put a >HUGE< directory listing into an Array. A directory with a million entries is a HUGE directory, I guess you only have a few thousand.
    I wouldn't bother reading the files into memory, you only need 2000 of them.
    Then I did a comparison for each file name in the list against the array. The OS will do this for you when you try to open the file, which you will have to do anyway to copy it.
    I know this cant be the most efficient way. More efficient way, don't do it at all.
    I posted earlier in the board but for some reason NO one answered. Perhaps the problem seemed too obvious.
    Can anyone suggest and easier way to do this?
    and what is the best way to copy files in java? Copy one at a time.
    opening a bufferwriter etc? Read a block of say 64K at a time. No buffers required.
    Essectially, im
    doing a restore from multiple backup directories to
    the original directory. Please help me if you can
    take the time.If you are recovering from a backup, the most important thing is ensuring the data is correct and valid, speed is less important. (It is no good if it is fast but corrupt)
    Coping 2000 files is going to be only as fast as your drive(s) can handle. How you copy the file is less important.

  • Best way to generate the XML files from a DTD file

    Hey,
    I am writing an application that needs to convert a complicated data structure into an xml file. I have design a DTD file that describes the data structure.
    My question is what is the best, most efficient way to covert the data structures (objects) into the XML files with a DTD file.
    Thank you very much.
    Candy

    Convert the DTd to an XML Schema. Generate java classes from Schema with Jaxb. Create an XML document from the java classes.

  • How do you validate XML file against a Schema?

    Are there free applications that does that?

    Thanks, but how do you validata the Schema itself, which is an XML file.
    I know the schema DTD is online, but still I need some utility to do it
    Thanks

  • Best way to access and share files...

    I have all my files in a folder currently in Macintosh HD > Shared Items > Folder Name... Should I be changing this and adding the folder into my group folders?

    Which image or file or document or content management system depends highly on your specific local requirements and users, what sort of information you're storing and retrieving and indexing and updating (images, documents, something else) and what your budget is.
    [Here|http://en.wikipedia.org/wiki/Contentmanagementsystem] and [here|http://en.wikipedia.org/wiki/Documentmanagementsystem] are general introductions, and with links in various directions.
    Depending on what you're doing, other examples can re-purposed source code control packages include Mercurial (Hg) and git.

  • URGENT---Validating XML file against DTD

    I have a XML & DTD file.I want to validate that xml file against the specified DTD without using any editor.Through program how can i validate?Pl. help me.It's URGENT.

    >
    and i recieved ORA-31001: Invalid resource handle or path name "/testdtd.dtd"
    when the DBMS_XMLPARSER.parseClob( PARSER , v_xml ); is executed
    i removed the <!DOCTYPE family SYSTEM "testdtd.dtd"> from the XML file
    the procedures worked , but not sure if really validated against the DTD file>
    you have to load your DTD into XDB repository.
    <a href ="http://forums.oracle.com/forums/thread.jspa?threadID=416366">How do I use DTD's with XML DB ?
    Ants

  • Is there a way to download an XML file from internet to internal table.

    Hi,
    We have Two system that first is "R/3 4.6C"   and   second is  "WebAS 6.20" and prior is first.
    I tried so much ways, i searched Function modules, classes, transactions ...
    But i have not found a way to download and XML file from internet like "http://www.tcmb.gov.tr/kurlar/today.xml" to internal table.
    is it possible to do ?
    if not, i will do with Delphi and RFC but i dont want to do this outside from SAP.
    thanks
    ibrahim

    Hi Ibrahim Bhai,
    I am Facing same kind of issue of getting Data of url into internal table.
    I want to know what are the settings that need to be made in SM59 to achieve this.
    What are the parameters that need to be passed while call to FM 'http_get' .
    Full Points will be rewarded.
    In Advance Thanks.
    With Regards,
    Shahrukh.

  • QUESTION: XML validation against a schema - for beginners

    Hi folks,
    i am new to XML validation.
    i would like to find out how to validate an XML file using a schema given to me by a third part company.
    the business process requires that our company sends a weekly file which complies with their schema.
    in real-life, i am expecting some details of our file to fail against their schema.
    thus i would like to find a way validating the file localy before sending it to this third part.
    this validation would ideally allow me to highlight and identify which records are failing the validation, and enable me to strip those and send only those that are successfully checked.
    on the example below, i would expect to have the record for John Smith to be successful (country has an integer); while Queen Victoria would fail as it uses UK instead of an integer to identify the country.
    thus i would need to find a way validating this XML file, move the record of Queen Victoria to another file to be fixed and to allow, the record for John Smith to be sent out.
    if you guys could post some links to where i can find further information on this type of processing, i would be most grateful.
    Many thanks,
    Nicolas
    using an example from:
    [http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c6737]
    XSD
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="address">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="street" type="xs:string"/>
    <xs:element name="city"type="xs:string"/>
    *<xs:element name="country"type="xs:integer"/>*
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>XML
    <address>
    <name>John Smith</name>
    <street>109 Abbey Close</street>
    <city>Hayes</city>
    <country>98</country>
    </address>
    <address>
    <name>Queen Victoria</name>
    <street>1 Regent Street</street>
    <city>London</city>
    <country>UK</country>
    </address>Edited by: www.jegue.net on Jan 13, 2009 9:48 AM
    Edited by: www.jegue.net on Jan 13, 2009 9:49 AM

    i would need to find a way validating this XML file, move the record of Queen Victoria to another file to be fixed and to allow, the record for John Smith to be sent out.I don't think any automated tool or API available with such features. You should achieve this by some tricky logic/code.

  • Best way to handle .properties and .xml files

    Hi,
    I have an application which contains so many properties and XML files, these are a part of WAR file which we deployed in
    tomcat server. Whenever we make changes to these properties and XML files we redeploy the app and start the server.
    Is there any way we can make sure that these files can take changes without redeploying or starting the server?
    Please clarify.
    Thanks.

    Sure - keep them outside of the war. Pick any directory where you can put them (a directory where the server is allowed to read of of course), load them from that directory in your application. Make sure you can reach that directory through (S)FTP to easily be able to modify them. Then all you need is a way to reload them in the application, should the information be cached.

  • Validate the input file against a given schema inside an orchestration and producing 2 different files based on the validation result

    HI All,
    I have a situation.
    I need to validate the input file against a given schema inside an orchestration and producing 2 different files based on the validation result.
    A predefined success schema in case of  validation success and negative schema structure for validation failure.
    any advice ?

    Hi Rachit,I following the blog
    http://dietergobeyn.be/validating-biztalk-messages-orchestration/ and stuck in few things
    I created a helper class with the name Validation and following code
    [Serializable]
        public class Validation
            private bool _isValid = true;
            public bool Validate(XmlDocument document, Type schema)
                XmlSchemaSet set = new XmlSchemaSet();
                if (typeof(SchemaBase).IsAssignableFrom(schema) && !schema.IsNested)
                    set.Add((Activator.CreateInstance(schema) as SchemaBase).Schema);
                ValidationEventHandler eventHandler = new ValidationEventHandler(HandleValidationError);
                document.Schemas = set;
                document.Validate(eventHandler);
                return _isValid;
            private void HandleValidationError(object sender, ValidationEventArgs ve)
                _isValid = false;
    public static bool ValidateMessage(XLANGMessage msg)
    XmlDocument xDoc = new XmlDocument();
    xDoc = (System.Xml.XmlDocument)msg[0].RetrieveAs(xDoc.GetType());
    Type t = typeof(Schemas.External.Invoice_v3_1);
    Validation validation = new Validation();
    return validation.Validate(xDoc, t);
    First thing, Do i need to write the ValidateMessage method inside the helper class or not ??
    If inside, how to add the reference of schema files in the statement (Type t = typeof(Schemas.External.Invoice_v3_1);)
     I tried adding the reference of my schema project but it is showing error.
    And what is to be written in the ValidateMessage expression shape in Orchestration ?
    Really appreciate your help.

  • How is the best way to backup and organize Adobe layered .PSD files on iMac OSX maverick?

    How is the best way to organize and backup Adobe layered PSD files on iMac desktop OSX maverick?
    I lost all my Adobe Photoshop files + everything else on my IMAC when it crashed. They reinstalled Operating System.  But now i must install programs such as MS Word & Adobe indesign suite.
    Please help me determine what is the bestway to backup Adobe layered  PSD files? I believe these are my choices to be assured this doesn't ever hapen again. Please comment.
    Buy Apple Airport Time capsule $280.  But I am not sure if it can store PSD layers. Can it or do you have to have Apple Apperture  software to act be sure layers are saved
    I had had trouble getting Adobe Cloud to sync to save files and so just trusted my computer to not ever crash.  Any hints on this procedure
    Are there any hints on PhotoShop image organization for a current IMac usser ?
    Please help.
    Teann  ucreateit

    My backup plan is to use Time Machine to make a backup to an external disk drive plus I also do a clone of my system disk. So far between the bootable clone and the Time Machine backup this plan has covered all of my needs.
    Allan

Maybe you are looking for