aspose file tools*
The moose likes XML and Related Technologies and the fly likes converting xml to xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "converting xml to xsl" Watch "converting xml to xsl" New topic
Author

converting xml to xsl

jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
hi,please check the following code.here i am not understanding how to see x1, its a xmlDocument.
if i try to print x1,its giving output as oracle.xml.parser.v2.XMLDocument@1ee3914.any body explain how to do exactly and how proceed.

import oracle.xml.differ.*;
import oracle.xml.parser.v2.*;
import java.io.*;
import org.xml.sax.SAXException;



public class First1 {

public static void main(String arg[])throws FileNotFoundException,IOException,XMLParseException,NullPointerException,SAXException{
DOMParser parser = new DOMParser();
XMLDocument x1=null;
XMLDocument x2=null;

InputStream catalog1 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\test1a.xml"));
parser.parse(catalog1);


x1 = parser.getDocument();
System.out.println(x1);


InputStream catalog2 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\test2a.xml"));
parser.parse(catalog2);



x2 = parser.getDocument();
XMLDiff a = new XMLDiff();


//a.setDocuments(xmlDocument1, xmlDocument2);
a.setDocuments(x1, x2);

boolean dif = a.diff();

System.out.println(dif);


/*
InputStream catalog1 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\test1a.xml"));
XMLDiff a = new XMLDiff();
parser.parse(catalog1);


XMLDocument x1 = parser.getDocument();
a.setInput1(x1);

XMLDocument x3=a.generateXSLDoc();
System.out.println(x3);
*/

}
}
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


The contents of the XML document would not be printed if you use System.out.println(). It would only print the Object along with the HashCode. You would have to iterate through the contents to get a more meaningful output.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
iterate means what.actually i want to use these methods to convert xml to xsl document.
after that i have to show the output in the form of xsl and differentiate two xml files.can you suggest me how to do.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Raj Kamal wrote:
The contents of the XML document would not be printed if you use System.out.println(). It would only print the Object along with the HashCode. You would have to iterate through the contents to get a more meaningful output.[/quotit

iterate means what.actually i want convert xml to xsl document and i want to get the difference between two xml files.
can suggest me please.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Iterate as in loop through elements in the XML.

Convert XML to XSL???

Differentiate two XML files???

jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Raj Kamal wrote:
Iterate as in loop through elements in the XML.

Convert XML to XSL???

Differentiate two XML files???



yes Differentiate two xml files.and we have methods in oracle.xml.xmldiff.so i want to know the usage of those methods.how can use it.and for ex: in this package
generateXSL

public void generateXSL(java.io.Writer out)
throws java.io.IOException,
java.lang.NullPointerException

Generates an XSL file of input filename which represents the differences between the 2 XML files which were set initially. The first XML file can be transformed into the second XML file using the XSL stylesheet generated. If the XML files were the same then the XSL generated will transform the first XML file into the second XML file, where the first and second files will equivalent.

Parameters:
out - Generated XSLT will be written to 'out'.
Throws:
java.io.IOException - could occur if the xsl file was not created successfully
java.lang.NullPointerException - could occur if input file name is null

how to use it. for this i created XMLDocument a1=new XMLDocument();
a.generateXSL(out);
but for out i have to create anything as like declaration or object. here writer type of out but writer is abstract class.
how can i proceed

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Create a FileWriter object and pass the reference to generateXSL().
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Raj Kamal wrote:
Create a FileWriter object and pass the reference to generateXSL().



i am netbeans

import oracle.xml.differ.*;
import oracle.xml.parser.v2.*;
import java.io.*;
import org.xml.sax.SAXException;
import java.io.FileWriter;



public class First1 {

public static void main(String arg[])throws FileNotFoundException,IOException,XMLParseException,NullPointerException,SAXException{
DOMParser parser = new DOMParser();
XMLDocument x1=null;
XMLDocument x2=null;

InputStream catalog1 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\test1a.xml"));
parser.parse(catalog1);


x1 = parser.getDocument();



InputStream catalog2 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\test2a.xml"));
parser.parse(catalog2);



x2 = parser.getDocument();
XMLDiff a = new XMLDiff();


//a.setDocuments(xmlDocument1, xmlDocument2);
a.setDocuments(x1, x2);

boolean dif = a.diff();

System.out.println(dif);


XMLDocument a1=new XMLDocument();


a1=a.generateXSLDoc();
a1.print(System.out);
/*PrintWriter out
= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Documents and Settings\\JA0084604\\Desktop\\test1a.xml")));
a.generateXSL(out);*/

FileWriter out=new FileWriter("");
a.generateXSL(out);
}
}

its showing error at a.generateXSL(out); method generateXSL(java.io.FileWriter); not found
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Cummon now, give a path/file-name to FileWriter().
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Raj Kamal wrote:
Cummon now, give a path/file-name to FileWriter().


if i give filename as file1 its showing error in next line cannt find method.please help me out i am new to xml
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


This has nothing to do with XML. You have to give a full path and filename when you create the FileWriter object (out).

Please use CODE tags when posting code otherwise it is so very hard to read.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
[0]
>here i am not understanding how to see x1, its a xmlDocument.


[1]
>so i want to know the usage of those methods.how can use it.and for ex: in this package
generateXSL
public void generateXSL(java.io.Writer out)
throws java.io.IOException,
java.lang.NullPointerException


You have also member functions which may be more useful in different settings, such as generateXSLDoc() or generateXSLFile()...

These are just for illustration of how to get XMLDocument or XMLDiff perform. I don't see any other way than studying their documentation. Speculation and guessing do not get you far.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:[0]
>here i am not understanding how to see x1, its a xmlDocument.


[1]
>so i want to know the usage of those methods.how can use it.and for ex: in this package
generateXSL
public void generateXSL(java.io.Writer out)
throws java.io.IOException,
java.lang.NullPointerException


You have also member functions which may be more useful in different settings, such as generateXSLDoc() or generateXSLFile()...

These are just for illustration of how to get XMLDocument or XMLDiff perform. I don't see any other way than studying their documentation. Speculation and guessing do not get you far.


here x1 is xmldocument and whatever you sent printwriter.i checked i got error as method not found a.generateXSL(pw);
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Raj Kamal wrote:
This has nothing to do with XML. You have to give a full path and filename when you create the FileWriter object (out).

Please use CODE tags when posting code otherwise it is so very hard to read.


i tried with path and filename also even same error getting.and please tell me how to use codetags
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
x1 and a are both your notations, not even mine. I don't what you are talking about... a.generateXSL() and x1, can we mix them all up?
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:x1 and a are both your notations, not even mine. I don't what you are talking about... a.generateXSL() and x1, can we mix them all up?


Actually what i am saying is x1 is a xml document and a is the object of xmlDiff class
and here what i did is i created x1,x2 XMLs and after that i differentiate with reference a(reference of xmlDiff)
i got a difference between two xmls(x1,x2)

then what my task is i want to use generateXSL(java.io.Writer);

with this method i will get the xsl of difference of two xmls (x1,x2).

please dont get irritate.if you dont understand what i written here.

or else tell me code how to use generateXSL(); and where i will get xsl.

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
>or else tell me code how to use generateXSL(); and where i will get xsl.

If I can recap what I said and condense it to one line:

Have you looked at System.out? (This line is positioned after a.diff() had been called.) If you had not and said it not working or something, there is no reason I am full of joy and say that's cool. I might or I might not be irritated --- that's all your words that have no concern as far as I'm concerned.

If you're not in a position to have a System.out console to look at, you may persist its output to a file for inspection. At the same time, I can show you more options the class exposed for your convenience.

or any of their variants as long as their constructor accepts.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:>or else tell me code how to use generateXSL(); and where i will get xsl.

If I can recap what I said and condense it to one line:

Have you looked at System.out? (This line is positioned after a.diff() had been called.) If you had not and said it not working or something, there is no reason I am full of joy and say that's cool. I might or I might not be irritated --- that's all your words that have no concern as far as I'm concerned.

If you're not in a position to have a System.out console to look at, you may persist its output to a file for inspection. At the same time, I can show you more options the class exposed for your convenience.

or any of their variants as long as their constructor accepts.


hi,
thanks i tried what you said

a.generateXSL(new PrintWriter(System.out));
a.generateXSLFile("C:\\Documents and Settings\\JA0084604\\Desktop\\outfile.xsl");
a.generateXSLDoc().print(new FileOutputStream("C:\\Documents and Settings\\JA0084604\\Desktop\\outdoc.xsl"));

but at the line of a.generateXSL(new PrintWriter(System.out));
getting error method as genterateXSL(java.io.printwriter) is cannt find.
i missed any imports for this?
i am not getting
and tell me a.generateXSLDoc(),a.generateXSLFile().
what is the difference between two methods. i am getting same output for these two.




g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
>and tell me a.generateXSLDoc(),a.generateXSLFile().
What do you mean by that, telling you?

>what is the difference between two methods. i am getting same output for these two.
Watch carefully the .print() method is used following generateXSLDoc() because generateXSLDoc() return an XMLDocument which is the xslt document (itself an xml document). That is the difference and that is also the detail intended to be shown otherwise I wouldn't bother. They by the full line written output of course the same xslt document that is what I want you to see alternative or looking at the same problem at different angle. It is not meant to be read casually.

If the generateXSL() line does not work for your version, just don't use it and comment it out. You have the other two lines to output the same already. It is probably related to the xdk you're using. That's all. You've to read your manual.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:>and tell me a.generateXSLDoc(),a.generateXSLFile().
What do you mean by that, telling you?

>what is the difference between two methods. i am getting same output for these two.
Watch carefully the .print() method is used following generateXSLDoc() because generateXSLDoc() return an XMLDocument which is the xslt document (itself an xml document). That is the difference and that is also the detail intended to be shown otherwise I wouldn't bother. They by the full line written output of course the same xslt document that is what I want you to see alternative or looking at the same problem at different angle. It is not meant to be read casually.

If the generateXSL() line does not work for your version, just don't use it and comment it out. You have the other two lines to output the same already. It is probably related to the xdk you're using. That's all. You've to read your manual.


you mean to say that generateXSLDoc() will return xml Document(which includes xsl) and generateXSLFile() will generate the xsl File.
if try to print xml Document will get xsl output.
and will get same output for both methods.is it rgt?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
>will get same output for both methods.is it rgt?
Apart from some (unsignificant) ignorable whitespaces related to formatting, they get the same output, an xslt doc.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:>will get same output for both methods.is it rgt?
Apart from some (unsignificant) ignorable whitespaces related to formatting, they get the same output, an xslt doc.


ok thanks alot for you are support.
and let me know how to use packages (ex: default package java.lang.object)has more methods.To use those methods in application. can you suggest me the way to learn. and also actually i didn't get any proper material(understandable examples) regarding oracle.diff.xmldiff package to apply those methods in application.

please suggest me how to work with packages properly.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
You can google for oracle xdk developer's guide. For 9i release 2 (9.2), this is the link:
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96621.pdf
whereas for 11g release 1 (11.1), this:
http://download.oracle.com/docs/cd/E15523_01/appdev.1111/b28394.pdf
You can too find 10g's.

If you care to read, you will discover that generateXSL() begins to appear from 10g. For 9i version, it is not yet entered into the spec.

Other than that I don't have anything to share on how to read and do. That sounds terribly pretentious.
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
g tsuji wrote:You can google for oracle xdk developer's guide. For 9i release 2 (9.2), this is the link:
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96621.pdf
whereas for 11g release 1 (11.1), this:
http://download.oracle.com/docs/cd/E15523_01/appdev.1111/b28394.pdf
You can too find 10g's.

If you care to read, you will discover that generateXSL() begins to appear from 10g. For 9i version, it is not yet entered into the spec.

Other than that I don't have anything to share on how to read and do. That sounds terribly pretentious.


thanks you so much.
 
jQuery in Action, 2nd edition
 
subject: converting xml to xsl