Results 1 to 2 of 2
  1. #1
    sarcasteak is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default Validate document starting at xpath

    Hi guys,

    I have an issue where I am trying to validate an xml document, but there is header information that I don't want it to validate. So I want to be able to tell it to start validating at a certain xpath location.

    xpathExpression contains the xpath link, but it seems to ignore it.

    Java Code:
    try {
        		DOMSource domSource = new DOMSource(doc, xpathExpression);
        	       StringWriter writer = new StringWriter();
        	       StreamResult result = new StreamResult(writer);
        	       TransformerFactory tf = TransformerFactory.newInstance();
        	       Transformer transformer = tf.newTransformer();
        	       transformer.transform(domSource, result);
        	       String docString = writer.toString();
        	
        		SAXBuilder builder =
                    new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
        		        builder.setValidation(true);
               
        		builder.setFeature(
                    "http: //apache.org/xml/features/validation/schema",
                    true);
        		builder.setFeature("http: //apache.org/xml/features/validation/schema-full-checking", true);
    
                builder.setProperty(
                		"http: //apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
    					new File(validationPath).toURI().toString());
                org.jdom.Document docx = builder.build(new StringReader(docString));
                this.wrong(rowCount,1, docString);
            	}
    	       catch (Exception ex){
    	    	   this.wrong(rowCount, 2, ex.getMessage());
    	    	   error = true;
    	       }
    I also am having a hard way figuring out how to make sure the document is validated properly.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you use the DOM methods rather than SAX, you can traverse to the node you want to start from and call validate on that. I've never used SAX myself.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Xpath and Xquery
    By Peter in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 03:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •