Comparing XML files to XSLT
I have a XML version of a document, and an XSLT version that represents the SAME document.
How can I compare them and check that they are the same in the JAVA?
Thanks.
Abder-Rahman wrote:
How can I compare them and check that they are the same in the JAVA?How would you do it NOT in Java?
If you know that, then when you get stuck writing the Java code to implement the algorithm, as a more specific question.
If you don't know how to do it NOT in Java, then you need to figure that out before coming here or even thinking about Java.
Similar Messages
-
How to update XML file using XSLT
Hi there,
I have a "small" issue with exporting data to an XML file using XSLT.
A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
Many thanks,
Ferenc
P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
XSLT approach: check these online tutorial
http://www.xml.com/pub/a/2000/08/02/xslt/index.html
http://www.xml.com/pub/a/2000/06/07/transforming/index.html
ABAP approach:
for example you have the xml (original) in a string called say xml_out .
data: l_xml type ref to cl_xml_document ,
node type ref to if_ixml_node .
create object l_xml.
call method l_xml->parse_string
exporting
stream = xml_out.
node = l_xml->find_node(
name = 'IDENTITY'
ROOT = ROOT
l_xml->set_attribute(
name = 'Name'
value = 'Charles'
node = node
(the above example reads the element IDENTITY and sets attribute name/value to the same)
like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
so how do I access the XML file in order to update it?
you have already read this XML into a ABAP variable right?
Sorry couldnt understand your whole process, why do you need to read local XML file?
Raja -
XML File in XSLT with dc:subject
Hi
How to Read the XML File in XSLT
is there any rule to read
what is this dc:subject
can any one give me a sample code to read this in XSLT for a jsp page
<?xml version='1.0' encoding='UTF-8'?>
<record xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:subject xml:lang='en'>
Science--Physics
</dc:subject>
</record>
Thanks
rajivNormally I would be happy to help you, but after several years of trying to help here, I've decided not to contribute anymore because of the piss-poor way in which this site is being administered.
Others are still helping, but more may leave if things don't improve. May I recommend devshed or javaranch?
http://www.devshed.com/
http://www.javaranch.com/
If you would like to complain to the admins of this forum, either click the "Report Abuse" link or the "Feedback" link.
-- foofoo (shamelessly stolen the text from jverd). -
How to find the existence of a tag in XML file through XSLT Mapping?
Hello Friends,
Working on an SAP XI interface ,I have come across a situation where I need to map the values only when a particular tag exists in the inbound XML file.I need to use the XSLT mapping for the same.
Requesting your advice on as to how may I validate the existence of a tag through XSLT mapping?
Thanks.Hello Friends
After research , I could also find another way to check the existence of a node .We can even use CHOOSE to check the existence.
<xsl:choose>
<xsl:when test="(/mynode)">
your action if the mynode is found
</xsl:when>
<xsl:otherwise>
action if mynode is not found
</xsl:otherwise>
</xsl:choose>
Thanks.
Wishes
Richa -
Recursively Merging 2 XML files with XSLT
Hi there, I'm having a problem with merging a couple of XML files. I've found a few examples of merging on-line but none that really help.
Basically I have an XML file which is written out by my Java program that looks something like this:
<alldata>
<data val="xx">
<data val="yy">
<data val="ss"></data>
</data>
<data val="gg"></data>
</alldata>The number of children and siblings can change by the way.
Therefore in the XSLT document I'm displaying the data recursively, i.e.
<tr><td><xsl:value-of select="@val"/></td></tr>
<xsl:for-each select="*">
<xsl:call-template name="itself"></xsl:call-template>
</xsl:for-each>This all works fine, but I now need to do a side by side comparison with another XML document that has exactly the same structure, but could have different values. I'm not sure how to do this, perhaps using the same recursive code and using a sort of pointer to where you are in the 2nd XML file (see below), but I've no idea how to go about this?
<tr><td><xsl:value-of select="@val"/></td>
<td><xsl:value-of select="<2nd documents @val>"/></td>
</tr>
<xsl:for-each select="*">
<xsl:call-template name="itself"></xsl:call-template>
</xsl:for-each>Output:
xx xy
yy yy
ss ss
gg hhDoes anybody have any suggestions or help on how to achieve this?
Cheers
DanI posted the same question on the xsl-list message list and got a working solution - here it is in case anyone else has the same problem:
<xsl:variable name="a" select="document('doc1.xml')//data"/>
<xsl:variable name="b" select="document('doc2.xml')//data"/>
<xsl:template match="/">
<table>
<xsl:for-each select="$a">
<xsl:variable name="p" select="position()"/>
<tr>
<td><xsl:value-of select="@val"/></td>
<td><xsl:value-of select="$b[$p]/@val"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>Cheers
Dan -
JSP XML file parsing XSLT using Xalan
Hi all
I have created an XML file "view_campaign.xml" using JSP as shown in a code below and i wanna know how i should proceed to parse the XML file and so i can display this XML as the XSLT file i created.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
// Identify a carriage return character for each output line
int iLf = 10;
char cLf = (char)iLf;
// Create a new empty binary file, which will content XML output
File outputFile = new File("C:\\WebContent\\view_campaigns.xml");
//outputFile.createNewFile();
FileWriter outfile = new FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
try {
// Define connection string and make a connection to database
//DriverManager.registerDriver (new org.apache.derby.jdbc.ClientDriver());
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
Statement stat = conn.createStatement();
// Create a recordset
ResultSet rset = stat.executeQuery("Select * From campagn");
// Expecting at least one record
if( !rset.next() ) {
throw new IllegalArgumentException("No data found for the campaigns table");
outfile.write("<campaigns>"+cLf);
outfile.write("<campaign>"+cLf);
outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
outfile.write("</campaign>"+cLf);
// Parse our recordset
// Parse our recordset
while(rset.next()) {
outfile.write("<campaign>"+cLf);
outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
outfile.write("</campaign>"+cLf);
outfile.write("</campaigns>"+cLf);
// Everything must be closed
rset.close();
stat.close();
conn.close();
outfile.close();
catch( Exception er ) {
%>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this is my .XSL file
<?xml version="1.0" encoding="iso-8859-1" ?>
- <!-- DWXMLSource="view_campaigns.xml"
-->
<!DOCTYPE xsl:stylesheet (View Source for full doctype...)>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
- <xsl:template match="/">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gestion des campagnes</title>
</head>
- <body>
Gestion des campagnes
- <table border="1">
- <tr bgcolor="#9acd32">
<th align="left">Code</th>
<th align="left">Nom</th>
<th align="left">Type</th>
<th align="left">Client</th>
<th align="left">Nombre de positions</th>
<th align="left">Date d'ouverture</th>
<th align="left">Date de cl�ture</th>
</tr>
- <xsl:for-each select="campaigns/campaign">
- <tr>
- <td>
<xsl:value-of select="campaign_id" />
</td>
- <td>
<xsl:value-of select="campaign_name" />
</td>
- <td>
<xsl:value-of select="campaign_type" />
</td>
- <td>
<xsl:value-of select="client" />
</td>
- <td>
<xsl:value-of select="positions" />
</td>
- <td>
<xsl:value-of select="begin" />
</td>
- <td>
<xsl:value-of select="close" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>I would be greatful that u answer my question what i should do have any exemple case study.Hi,
Try this code
JspWriter out = pageContext.getOut(); // Get JSP output writter
javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); //Instantiate a TransformerFactory.
String realPath = "c:/applyXsl.xsl";
java.io.File file = new java.io.File(realPath); // crearte a file object for given XSL.
// Use the TransformerFactory to process the stylesheet Source and generate a Transformer.
javax.xml.transform.Transformer transformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource(file));
java.io.StringReader inputStream = new java.io.StringReader("c:/xmlFile.xml"); // create an input stream for given XML doc
java.io.ByteArrayOutputStream obj = new java.io.ByteArrayOutputStream(); // Create an output stream for XSL applied XML doc.
// 3. Use the Transformer to transform an XML Source and send the output to a Result object.
transformer.transform(new javax.xml.transform.stream.StreamSource(inputStream), new javax.xml.transform.stream.StreamResult(obj));
String outputString = obj.toString(); // get the XSL applied applied XML document for print
out.println(outputString); // print the XSL applied XML in to JSP.
however you need xercesImpl.jar and xml-apis.jar files to run this program.
Regards,
Ananth.P -
Compare xml file database data
Hi all,
Just wondering is it possible using jsp to compare the contents of an xml file to a database table if they are similiarly laid out?Select the type of dataset :)
You have to place the xml file in the location you specified in Admin tab.
You can create a new dataset, type : based on XML file. -
I am testing an application that read a XML file and creates another XML file. In the test I would like to verify that the created XML file is identical to the read XML file. Are there any unit testing packages for Java/eclipse that deals with this kind of problem?
JoachimSauer wrote:
I heard that XMLUnit is pretty useful for this.+1
Particularly, look at the classes Diff and DetailedDiff. -
Hello,
I am trying to insert a XML file into the tables. When I read the XSU documentation, I saw a command line utility java OracleXML.
In a book I read, it said before one uses java OracleXML commmand line utility, the XML file has to be converted to another XML file using XSLT for OracleXMLSave to recognize the XML file. This was because OracleXMLSave will know to insert the XML file into the tables only if the XML was generated by OracleXMLquery.
But in the Oracle XML documentation, it didn't explicitly say anything about converting using XSLT to do the loading of the XML file into the tables. But the examples in the site used only the XML file which was generated from the tables to load them into the table again.
Please clarify me on this point.
Thanks a lot for your help.
RamaUsing the Oracle XML DB Webdav are is one method as it acts like a file system, but essentially get's the documents directly into the database so they can be queried through the resouce_view.
Other methods involve reading the file as if it's a CLOB and then using XMLTYPE constructor to change that CLOB to an XMLTYPE which can then be stored as that datatype in the database or processed as you need.
The best place to look is over in the XML DB forum, which has it's own FAQ detailing various best practices for all sort of XML stuff, including reading XML files and shredding them into relational tables etc.
{thread:id=410714}
Edited by: BluShadow on 18-Jan-2012 08:53
corrected link -
Transfer 100M XML file with XSL
Hi,
I am trying to transfer 100M XML file with XSL. Input.xml is the XML file, format.xsl is the XSL file. I type in the command line as:
java org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
It got "out of memeory" error. My questions are:
1. Is it possible to transfer such large XML file with XSLT?
2. The XSL processor used SAX or DOM to parse XML file?
3. Any suggestions?
Thanks.
Jamesmaybe?
java -Xmx200m org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java-classic.html -
How to convert xml file to xsl using java
Hi all,
I have an XML file with which i need to convert(transform) it to an xsl file using java.
I am new to converting xml file to xslt.Please send me if u have code .
Thanks in advance
regards
RamYou seem to be asking the wrong question. An XSL file can be used to transform an XML file, but transforming an XML into an XSL does not make sense. The API for running XSL transforms on the Java platform is described here:
http://java.sun.com/javase/6/docs/api/javax/xml/transform/package-summary.html -
Java source code to compare XML based on ExamXML XML diff tool
I’m working on a project that includes comparing XML files and I need a source code on Java to compare XML fragments.
I’m using ExamXML from http://www.a7soft.com to compare XML files but I need the Java source code.
Can anybody help me.You didn't notice there's a "Support" link on that page you referred to? Ask them for the source code. If they won't give it to you, then you are effectively asking us to give you a stolen copy of it. Don't ask for such things on this site.
-
HO w to use SAX parser to create an XML file on the fly
Hi All,
Currently I am using the DOM parser to create an XML file from a text file. But as the DOM takes much memory and inefficient, I need to convert the DOM translator to SAX translator. Can I do that ?? If YES then how to go about that and if NO then what may be the workaround for that.
Please help me out
Thanx in advance
kaushikIncidentally, look at this thread:
http://forum.java.sun.com/thread.jsp?forum=34&thread=252415
It has an example of how to transform an XML file via XSLT. If you change this to use the zero-argument form of newTransformer, it will apply the "identity transformation" to your input, thus outputting your XML in valid form. Now you just need to figure out how to provide SAX input to this, and the JAXP download includes an example of that. -
XSLT mapping code to replace ns1: tag as plm: in XML file in PI mapping
Hi
I am sending XML file to HTTP server as below format
<?xml version="1.0" encoding="UTF-8" ?>
- <ns1:Responses xmlns:ns1="http://">
- <ns1:Response Application="SAP">
<ns1:field1>12345</ns1:field1>
<ns1:field2>abc</ns1:field2>
- <ns1:Items>
<ns1:doc></ns1:doc>
</ns1:Items>
</ns1:Response>
</ns1:Responses>
i hve to replace <ns1: as <plm:, i could able to delete <ns1: tag uisng XSLT mapping(in sdn), but i dont know how to add tag with <plm:
Hi XSLT experts/if any has come across this requirment, please send XSLT code to add tag in XML.
Regards,
RajeshNo need for XSLT, just use the XMLAnonymizerBean module in your receiver communication channel.
http://help.sap.com/saphelp_nw70/helpdata/EN/45/d169186a29570ae10000000a114a6b/frameset.htm
/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean
If your receiver CC cannot process modules (ABAP receiver, for example), in your XSLT just define the target namespace with the desired prefix.
Regards,
Henrique. -
How can I compare the actual and expected values in Unit testing when they are XML files?
I have created a unit test for a method in VS 2008. My expected value and actual value are XMLs. Therefore though the output is same as I expect it gives an error as I am doing string comparison now. How can I compare these 2 XMLs in expected output and
actual output format in Unit Testing?
mayooran99In unit test, when you want to validate XML files, you feed them into the class / struct that you want to feed the XML into and compare the values there (You don't just feed it in XMLReader and feed it line by line, right? But if it really is, that's how
you should also test it in unit tests).
In short, how you'd use the XML in your code, that's how you should test it in unit test.
Maybe you are looking for
-
POPUP after selecting button in ALV
Hello everyone. I have an ALV (called with FM 'REUSE_ALV...') with a gui status of its own. I added a new button that must popup a window with information on some variables i just ended calculating. I allready tried using 'call screen' and the comman
-
External hard drive crashed...need to move iTunes music files
I had all my music on an external hard drive which recently crashed. Fortunately I did have the library xml file on my laptop hard drive so I still have the library info, playlists, play count, etc. So I used 3rd party software to dump the music file
-
Login with oracle.jbo.DMLException ??
dear all, I use oracle jdeveloper 11g 2 release and oracle 10g db. my db connection name is myDataSourceDS. And also weblogic server data source name also myDataSourceDS. but earlier my db connection name is ' ConLibr '. but after i change it accordi
-
Save keynote as word document?
In Powerpoint, it's a snap to send a presentation to Word and save it there (very convenient when you want to e-mail the presentation as a simple text document.) In Keynote, there seems to be no way to save, copy, or send a presententation as/to Word
-
How to set the Server CLASSPATH?
Hi all Oracle Java experts, I know this is a rather stupid questions: Where can I set the CLASSPATH of the Servlet Engine in Oracle 8.1.7.? I spent hours now searching the documentation and found loads of hints what to add to the CLASSPATH in which c