This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Websphere and the fly likes Validating XML file with XSD from WebContent, need help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Validating XML file with XSD from WebContent, need help!!" Watch "Validating XML file with XSD from WebContent, need help!!" New topic
Author

Validating XML file with XSD from WebContent, need help!!

jorge ruiz
Greenhorn

Joined: Dec 12, 2011
Posts: 4
Hi!

I'm trying to read one xml file from source WebContent, and to do it i need to know the relative path of the file or maybe the context, but i don't know how to do it.

Now i'm using this code:

String rutaXSD = "C:/Documents and Settings/user/Escritorio/Nueva carpeta/validateXML.xsd";

SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaLocation = new File(rutaXSD);

Schema schema = factory.newSchema(schemaLocation);


// 3. Get a validator from the schema.
Validator validator = schema.newValidator();

// 4. Parse the document you want to check.
InputStream in = new ByteArrayInputStream(param.getBytes("ISO-8859-1"));
Source sourceP = new StreamSource(in);

// 4. Parse the document you want to check.
//String input = "C:/Documents and Settings/user/Escritorio/Nueva carpeta/validateXML.xml";
//Source source = new StreamSource(input);


// 5. Check the document
try {
validator.validate(sourceP);
System.out.println("El xml recibido por parámetros es valido.");
} catch (SAXException ex) {
System.out.println("El xml recibido por parámetros no es valido porque ");
System.out.println(ex.getMessage());
} catch (Exception e) {
System.out.println("Ha ocurrido una excepción no controlada: ");
System.out.println(e.getMessage());
}

As you can see in this example i using the absolute path for de xml and the xsd files, and works fine, but the problem comes when i try to locate this files with the relative path. I'm suing Webspher V7 or WAS7 if you like.

Can you help me??

Thanks!!

PD: Sorry for my english.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
http://www.javaranch.com/name.jsp


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
jorge ruiz
Greenhorn

Joined: Dec 12, 2011
Posts: 4
Akhilesh Trivedi wrote:http://www.javaranch.com/name.jsp


Thanks, i didnt read that.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Relative path? You mean relative to Websphere's current working directory? Don't do that, you don't know what the CWD is. Anyway that wouldn't make sense based on the paths you mentioned in your post because they are completely unrelated to Websphere.

Or perhaps you meant something different than that?
jorge ruiz
Greenhorn

Joined: Dec 12, 2011
Posts: 4
Paul Clapham wrote:Relative path? You mean relative to Websphere's current working directory? Don't do that, you don't know what the CWD is. Anyway that wouldn't make sense based on the paths you mentioned in your post because they are completely unrelated to Websphere.

Or perhaps you meant something different than that?


Actually i don't know what CWD is...but the paths i posted here are just an example, i mean im working with that code but the files that i want to locate they must be in other source, not in desktop. The paths i want to use, the files, are within websphere's source project.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

CWD == Current Working Directory. And no, you don't know what it is.

But what's this "source project" you're talking about? Websphere doesn't have such a concept, as far as I know. Did you mean the files are part of a web application?
jorge ruiz
Greenhorn

Joined: Dec 12, 2011
Posts: 4
Paul Clapham wrote:CWD == Current Working Directory. And no, you don't know what it is.

But what's this "source project" you're talking about? Websphere doesn't have such a concept, as far as I know. Did you mean the files are part of a web application?


jejejeje i didnt know.

Well, about the source issue, perhaps my english is the problem here.

When i said source i mean folder or something like that, i have my project in one folder and the files i want to locate are in other folther, both are inside my work space.

The problem is that i can not use servletContext.getRealPath or similars because i dont hace any servlet cause im working with one webservice, and its no have any servlet.

I hope you understand my poor english :)

Thanks!!


By the way i added some picture, may come in handy.


[Download Dibujo.bmp] Download

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating XML file with XSD from WebContent, need help!!
 
Similar Threads
valiating xml using multiple schemas
validating xml
Unable to validate XML against the schema
pom.xml is not valid because cvc-elt.1: Cannot find the declaration of element 'project'.
XSD validation in XML