Can't validate xml file

Hi
My problem is that I'm not able to validate my xml file using example code taken from java.sun.com page:
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/package-summary.html
The source code is:
// parse an XML document into a DOM tree
    DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = parser.parse(new File("instance.xml"));
    // create a SchemaFactory capable of understanding WXS schemas
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    // load a WXS schema, represented by a Schema instance
    Source schemaFile = new StreamSource(new File("mySchema.xsd"));
    Schema schema = factory.newSchema(schemaFile);
    // create a Validator instance, which can be used to validate an instance document
    Validator validator = schema.newValidator();
    // validate the DOM tree
    try {
        validator.validate(new DOMSource(document));
    } catch (SAXException e) {
        // instance document is invalid!
    }My XSD file:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema">
     <element name="parent">
          <complexType>
               <sequence maxOccurs="unbounded" minOccurs="0">
                    <element name="child" type="string"></element>
               </sequence>
          </complexType>
     </element>
</schema>..and my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<tns:parent xmlns:tns="http://www.example.org/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/schema schema.xsd ">
</tns:parent>..and the error message:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'tns:parent'.
     at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109)
     at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:104)
     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
     at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:335)
     at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
     at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:347)
     at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:159)
     at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:337)
     at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.process(ValidatorImpl.java:220)
     at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:141)
     at javax.xml.validation.Validator.validate(Validator.java:82)
     at main.XMLValidation.main(XMLValidation.java:42)I've lost any ideas. What's wrong?????????? HELP
ania

I am also using rsaft_pt_xml to generate audit file for Protugal project. The xml file losing </auditfile> and </masterfile> tag. In that case,  the xml file can not be display correctly. We also have patched the sap notes to "1543036 - SAFT-PT Corrections RSAFT_PT_XML for 2010 (16)", but it does not work. Do you know how to solve this issue?

Similar Messages

  • I am wondering if there is a way to validate XML file without using .......

    I am wondering if there is a way to validate XML file without using the <!DOCTYPE... but pass in the location of the schema/DTD file as a parameter to a validating method?
    thanks

    None that I know of. The only thing close is to use the EntityResolver interface where you can modify the location of the DTD file before it's being loaded and parsed, but that requires a <!DOCTYPE ...> in the XML file.
    Good luck.

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • 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

  • Can you edit xml files in adobe contribute

    can you edit xml files in adobe contribute

    No, you can't even open them in recent versions of PSE.

  • Can't change xml file

    I am trying to import files from an external drive. I was able to do the add file to library from the drive but whenever I reload itunes it expects the files to be on my external drive which I have removed. I tried to change the location of the files in the itunes music library xml file but everytime I bring up itunes it changes the file location back to the original file on the external hard drive. I physically copied the files from the external drive to my itunes directory but itunes refuses to let me manually change the xml file to reflect the new location. Does anyone have a clue as to how I can update the xml file to point to the itunes directory for these imported songs rather than pointing back to the external drive?

    Bart_Blommaerts wrote:
    2: I set the "&#235 ;" value myself ..The problem setting this value in your Java code is that ... &#235; cannot be used to escape anything in Java, it only can be used to escape characters in an XML file.
    This is why an XML parser will automatically translate this value for you when it parses the XML file. The dom4j Document object will never see this value and when you do a getText() the resolved value is returned.
    Instead in Java you should use either the '�' value (make sure to save your Java files as Unicode) or you could use the Java way to escape characters: \u00EB.
    I was satisfied with the "�" in my XML file ... but when I deployed the application to the webserver .. and generated an XML-file I read "��", which is definitely not what I want ..
    So on my local Tomcat5 server I get "�". On the SunWappserver I get "��".This seems to be a different problem. When you read the file, you will have to make sure to read the file with the encoding that it was saved in. This means that the editor that you use to read the file will have to be able to read files encoded using UTF-8 (Unicode).

  • Is there any script or batch program that can pick a xml file...

    Hi,
    Is there any script or batch program that can pick a .xml file from a folder and place it in a different folder on the same directory periodically without using an XI interface.
    Thanks,
    np

    Hi Nadini,
    Please refer below link for how to sechdule a batch file.
    [Schedule Batch File-How to?|http://www.tech-archive.net/Archive/WinXP/microsoft.public.windowsxp.general/2006-04/msg01349.html]
    And please refer below links for how to write a batch file and other one as batch file commands.
    http://www.wikihow.com/Write-a-Batch-File
    http://www.aumha.org/a/batches.php
    these two links was a click away in google :).
    regards
    Aashish Sinha

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

  • Validate xml file authenticity

    I am sending out a standalone player that uses an xml driven image gallery. I need to prevent changes to the xml file to stop images being added to the gallery. I can can password protect the xml file to prevent changes, but I also wondered if there was a way to validate the authenticity of the xml file from within Flash to prevent the entire file being replaced?
    Brian

    First of all, if you password encrypt the xml file, and that file is replaced, it probably is not encrypted anymore, or another key is used. That would result in an error, which should be enough to send out a warning to the user.
    As an alternative, you can use an MD5 hash. You use the original XML file to create the hash, and when you read the file the hash should be the same. I don't think that this is any safer or better than your solution. Yeah someone could decompile the movie, replace the hash, but how many of your users will have the knowledge and time to do something like this?

  • Can not validate XML against schema

    Hi all,
    I'm new to XML validation. I have this sample from net.
    this is the schema definition:
    <xs:schema targetNamespace="http://www.w3schools.com" elementFormDefault="qualified">
    <xs:element name="note" type="xs:string"/>
    </xs:schema>
    and this is the xml file:
    <?xml version="1.0"?>
    <note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com note.xsd">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    when i try to validate at http://schneegans.de/sv/, this is a validator i found searching
    it gives error
    The root element does not comply with the schema. (2:2)
    any ideas?
    i have created my own xml and schema.I registered the xsd on oracle 10g but i get the same error :(
    where can i validate my xml against a schema?
    thanx a lot

    Validating XML Documents Against XML Schema
    http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html

  • Can not find xml file in classpath

    Hi,
    Can someone tell me how I can please or find a xml file in de webdynpro classpath: I have to place a xml and jar files in the classpath. The jar files are found in the application, but I get the following error: com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Unable to read the License file, please verify that you have SyncExLicense.xml file and it exists in the classpath or under com/yash/license folder.
    How can I check if this file is available in the classpath.
    Richard

    hi,
    have you check that all jar files are present or not.
    because when u import par file in to nwds it wont include jar files in that manully you have to import them.
    jayesh talreja

  • How can I create xml file automatically from database

    Hi,
    Can I create a site map drom database.There is table for storing menu details.Is it possible to create an xml file corresponding to a query.
    How can i configure root menu.xml to incllude this xml file.Please help me..
    Thanks

    Is your question pertaining to an answer regarding JDeveloper, or you just want an XML file? If XML, have you considered looking at the Oracle db XML DB feature set?
    CM.

  • Can I load xml file from SWC without using @embed

    I'm developing a mobile application in which I need to load xml files from File.applicationDirectory. This works great if the xml files are part of the main application swf. But I would like to move these xml files into a SWC so they could be shared across multiple applications.
    Using FlashBuilder 4.5, when a SWC is built, I can specify files to embed in the library that are not assets (Assets Tab of Flex Library Build Path). For various design reasons, I do NOT want to embed the xml files via @embed.
    When the swc is built and I open it up using a zip utility, I see the xml files in there just fine. So they are being bundled with the SWC. But how can I load these files in my main application that does not involve using @embed? When the main application is built, the swc setting for link type is "merged into code".
    I wouldn't expect the application to automatically pull out the xml files from the swc and place them in the File.applicationDirectory on the mobile device. I've tried loading from there just in case but file.exists is false (as expected).
    I've searched the web (and continue to do so) and all the answers seem to be to use @embed. Is there another way?
    Randy

    It's actually a lot easier than you think.
    Just reference the file like any'ol URL using a path relative to the SWC's src directory.
    So if you include the file "assets/xml/some.xml", just use that same string like you would any remote resource.
    For example:
    var loader:URLLoader = new URLLoader( new URLRequest("assets/xml/some.xml"));
    I believe it would also work like this "/assets/xml/some.xml", but I prefer relative paths so the link doesnt break if moved out of the SWC...

  • Can't parse xml file in jar file when  can't connect to web server

    My JNLP application throw ConnectException when trying to parse xml during web server offline.
    Steps,
    1. JNLP application has been launched once and all related jar and xml files are already downloaded to local cache.
    2. Then I close web server to test offline launch.I launch the JNLP application using shortcut with -offline parameter.
    3. However the JRE internal xml parser tries to connect to web server and report connection error as web server is down now.
    My concern is the file is already in the cache, why java still try to connect URL. This error happens in JRE 1.5, but it doesn't happen in JRE 1.6. It only happens when web server is down in JRE 1.5.
    I think it may be a bug of JRE, do any one can give me some hint about how to resolve?
    Thanks in advance!!
    I also moved the code piece to a simple web start example, following it the error and code pieces.
    Error Trace in Java console,
    ava.net.ConnectException: Connection refused: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(Unknown Source)
         at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at sun.net.NetworkClient.doConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
         at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
         at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
         at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
         at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
         at EntXmlUtil.buildDocument(EntXmlUtil.java:57)
         at Notepad.testParseXML(Notepad.java:870)
         at Notepad.main(Notepad.java:153)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at com.sun.javaws.Launcher.executeApplication(Unknown Source)
         at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
         at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
         at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
         at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
         at com.sun.javaws.Launcher.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Notepad.java
    public void testParseXML() {
         URL xmlURL=Notepad.class.getClassLoader().getResource("xml/Login.xml");
         try {
                   org.w3c.dom.Document doc = EntXmlUtil.buildDocument(xmlURL);
                   System.out.println("Test"+doc);
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    EntXMLUtil.java
    private static DocumentBuilderFactory dbf = null;
         static {
              dbf = DocumentBuilderFactory.newInstance();
              dbf.setNamespaceAware(true);
              dbf.setValidating(true);
              dbf.setIgnoringComments(true);
              dbf.setIgnoringElementContentWhitespace(true);
    public static DocumentBuilderFactory getDocBuilderFactory() {
              return EntXmlUtil.dbf;
    public static Document buildDocument(URL url, String systemId) throws Exception {
              DocumentBuilder db;
              Document doc;
              InputStream is;
              String sysId = null;
              if(systemId == null)
                   sysId = url.toExternalForm();
              else
                   sysId = systemId;
              db = EntXmlUtil.getDocBuilderFactory().newDocumentBuilder();
              is = url.openStream();
              doc = db.parse(is, sysId);
              is.close();
              return doc;
         }

    I finally got a temperary work around for this issue, using JRE5 version lower than update 16(not include update 16).
    i found Sun modify the URL which returned by XXX.class.getClassLoader().getResource("xml/Test.xml,") after update 15, previous it is related with the cache path, like C:\Users\epenwei\AppData\LocalLow\Sun\Java\Deployment\cache\javaws\http\Dlocalhost\P80\DMEntriView\DMapp\AMNotepad.jar!/xml/Test.xml, but after it changes to network path, like http://localhost/Notepad/app/notepad.jar!/xml/Test.xml. However, the latter address doesn't work in Sun's own class com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity if offline.It tried to create new URL then connect to web server. So exception is thrown since web server is down.
    if (reader == null) {
    stream = xmlInputSource.getByteStream();
    if(stream != null && encoding != null)
    declaredEncoding = true;
    if (stream == null) {
    URL location = new URL(expandedSystemId);
    URLConnection connect = location.openConnection();
    if (connect instanceof HttpURLConnection) {
         setHttpProperties(connect,xmlInputSource);
    I am not sure whether it is a Java new bug since I only read the codes and didn't debug Sun code. But I am very curious that I have already specify <j2se version="1.5.0_12" href="http://java.sun.com/products/autodl/j2se" /> to specify update 12 for my jws application. And I also see the Java console display like following
    Java Web Start 1.5.0_18
    Using JRE version 1.5.0_12 Java HotSpot(TM) Client VM
    Why java still uses my latest jre lib to run my application?
    Edited by: wei000 on May 22, 2009 5:32 AM

  • 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

Maybe you are looking for

  • Are these common problems with the 3g?

    So I had the old iPhone and absolutely loved it! I get the new one after waiting a few weeks so there was actually some available. Anyways, I had some problems with it when I got it and took it to my local apple store and they fixed is supposedly! Pr

  • FireFox 3.6.16 still not working with Flash!

    Since updating to the latest version of FireFox 3.6 I have not been able to watch flash video's on YouTube and other sites, also any flash based content is blank or black. I'm using Mac OS X 10.5.8 on a G5 PPC so Flash 10.1.102.64, the latest for PPC

  • JMicron JMC250 gigabit adapter - link not working

    I got a Sager NP8130 laptop that has a JMicron JMC250 gigabit ethernet adapter in it and have just installed 64-bit arch. From everything i've read, the "jme" module is supposed to work with this adapter. My system loads it, lsmod | grep jme shows it

  • English language implementation

    Dear programmers, I want to implement English language feature in the following applicationhttp://www.codeproject.com/Articles/714651/Desktop-Sharing-using-RDP-APIs-and-Socket I followed this http://stackoverflow.com/questions/12929934/same-resource-

  • My Microsoft Office 2004 stopped working after upgrading to MT.  How can I get it to work, or, how can I uninstall MT?

    My Microsoft Office 2004 stopped working after upgrading to Mountain Lion.  How can I get it to work again, or, how can I uninstall MT?