Creating XML from java Code
Hello @ll,
I need a java code to convert XML file ,which has one node to again a XML file with multiple nodes,depends on the content of source XML File....
The source structure is something like this:
<Name>abcd;xyzw;prs</Name>
and the target structure is something like:
<FirstNAme>abcd</FirstNAme>
<MidNAme>xyzw</MidName>
<LastName>prs</LastName>
the length of the data is not fixed. and ";" is used as a seperator.
I have hundred such nodes on the target side.
How do i acheive this
Thanks in Advance.
With Regards,
BVS
DEVELOPEMENT-THRILL wrote:
hi ,
what i think he can convert the xml to java object by using xstream then he can do his desired work in java and again he can convert it to xml by using xstream again.
RegardsAn enormous waste of time, though. His "desired" work doesn't need any Java at all, beyond maybe kicking off the transform. Seriously, you've given some poor advice - as we all do from time to time - just accept it rather than try to justify it in retrospect. One of the biggest mistakes you can make as a developer is to use the same tool for everything simply because you already know how to. XSLT and XPath are enormously useful tools to have kicking about, and pretty trivial to learn as well. What could take dozens of lines of Java to achieve could take a single XPath query. Which would you prefer?
Similar Messages
-
Hi
I want to use xml for updating files in an existing jar . so i want to call xml from java code and then come back to java code and do the remaining work in java code, pl guide me how to do this . what APIs are helpful for this regard
ThanksYou can't update files in a jar. Even if you could, you wouldn't use XML for that. You don't call XML. XML is not a programming language. So, basically your entire question is misguided.
-
How to modify an existing xml file from java code.
Hi
I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
For example if xml file(studlist.xml) is as below:
<?xml version="1.0" encoding="UTF-8"?>
<StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
<Student>
<Name>ram</Name>
<Age>27</Age>
</Student>
<Student>
<Name>sham</Name>
<Age>26</Age>
</Student>
</StudentList>
Now suppose i have set name to victor using student.setName,
and set age to 20 using setAge from javacode,
the new xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
<Student>
<Name>ram</Name>
<Age>27</Age>
</Student>
<Student>
<Name>sham</Name>
<Age>26</Age>
</Student>
</StudentList>
<Student>
<Name>victor</Name>
<Age>20</Age>
</Student>
As observed this is not a valid xml file.But how can i modify without any errors?I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
// gets the root element of the specified file (code not shown)
Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
// write a new student element
Element student = document.createElement("Student"); // creates the new student
rootElement.appendChild(student); // ***appends it to the root element***
Element name = document.createElement("Name"); // creates the name element
name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
student.appendChild(name); // appends the name to the student
Element age= document.createElement("Age"); // creates the age element
age.appendChild(document.createTextNode("26")); // adds the age text to the age element
student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM -
Generation of xml file from java code
hi,
I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?Let me know which parser are you using currently for reading xml files so that i assist you. For now, you can refer to STAX Parser API under this link
http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html -
Create web service from java code in Jdeveloper 11.1.1.5
I am try to create web service from java code by default it is connected to Integrated web logic server and generate a
WSDL like this.
http://localhost:7101/javaexcel-project1-context-root/MyWebService1Soap12HttpPort.
please tell me how we can change this local host to our needed Host and how to deploy this web service to web logic server.Hi,
Just right click on your project and deploy it to your application server (Weblogic Server (Not the Integrated server)). {Before that, you have create your Application server connection in the Jdeveloper).
After deployment open the Admin console of the weblogic server and find your ear of the project.Click on that (Go to the "Testing tab") and you will get the "WSDL" (Concreate wsdl) and "Test Client" of the Project. -
Help:create tree node dynamically from java code...
hi there...can anyone give me solution how to create or add tree node dynamically from java code???
currently i am using tree node to handle my menu...i try to create tree and add treenode dynamically from .java page, but it failed...can anyone give solution how to create tree ui from java code, so i can create a dynamic menu...thanz before...Hi:
Just put the statements you would normally put on a sqlplus command line in jdbc statements and execute them?
http://www-db.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html#0.1_executeUpdate
MJG -
Can u access Oracle9i Reports objects from Java Code?
Hi,
How can you access Oracle9i Reports (Rel 2) objects like Body, DataSource, Groups etc from Java Code?
What are the available APIs?
I went thru the APIs at http://otn.oracle.com/products/reports/htdocs/getstart/docs/Javadocs/oracle/reports/plugin/definition/package-summary.html
However various constructors stated in these APIs are using classes from "oracle.reports.definition" package which are difficult for me to locate.
For eg. Report constructor is using oracle.reports.definition.RWReport and there is no API documentation available for RWReport class.
Please suggest me the site for the above APIs or the method to get a reference to "Report" instance.
Thanks
Rakesh.Thanks Tugdual for your quick reply.
Thats exactly what I am trying to do. I want to develop a utility which can have a subset of Report Developer's functionality.
Currently using Reports Developer & Report Wizard, I can create a report by providing SQL statement and few parameters (like Report Style, Calculated Fields, Template file etc). I want to put all these parameters in a XML file and run my java utility (based on the APIs which I am looking for) which will use these XML parameter file and generate a '.rdf' file.
Also, could you please suggest me the site for oracle.reports.definition package API or the way to get a reference to oracle.reports.plugin.definition.Report instance.
Thanks,
Rakesh -
Creating XML from JDBC resultset
Can anyone give me a pointer as the best way to create XML from a JDBC resultset. I have told that XSU cannot be used as it is vendor specific and ties us to Oracle (yawn, yawn).
Any ideas welcomed.import javax.xml.parsers.*;
import org.w3.dom.*;
import javax.xml.dom.*;
import javax.xml.dom.source.*;
import javax.xml.dom.stream.*;
import java.sql.*;
public class CreateXML{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.newDocument();
Element root=doc.createElement("root_element");
// coonect to database
//get resultset metadata rsmd
while(rs.next()){
Element row=doc.createElement("row");
for(int j=1;j<=rsmd.getColumnCount();j++){
String colName=rsmd.getCoulmName(j);
String colValue=rs.getString(j);
Element e=doc.createElement(colName);
e.appendChild(doc.createTextNode(colValue));
row.appendChild(e);
root.appendChild(row);
doc.appendChild(root);
//You can now use XSLT to generate xml file thus:
TransformerFactory tmf=TransformerFactory.newInstance();
Transformer tf=tmf.newTransformer();
DOMSource source=new DOMSource(doc);
StreamResult result=new StreamResult("name of file for output");
tf.transform(source,result);
// of course exceptions will have to be caught in this code. -
Executing a DDL statement from java code
Hi all,
this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
I am trying to create a table in same schema in same db by using 'Copy' command.
Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
public String cmb_action() {
// Add event code here...
try {
//getting source db connection
InitialContext initialContext = new InitialContext();
DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
Connection sourceconn = ds.getConnection();
sourceconn.setAutoCommit(false);
String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"
Statement stat = sourceconn.createStatement();
stat.executeUpdate(sql);
sourceconn.commit();
System.out.println("done");
catch (Exception ne) {
// TODO: Add catch code
ne.printStackTrace();
return null;
}I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
But,
Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
Etc, etc,
Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
Regards
Peter
P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there? -
Clear the Filter Criteria from java code programmatically
Hi All,
I am using jdev version 11.1.1.6.0.
I do have ADF table for which I have added filter to each column .
I created table using java class data control.
Filter is working Fine .
My use case is-
When I click on search button data is populated in table.
When anybody enters filter value in column suppose product and hit enter ,it filters data.
if he clears and do not hit enter key and search again then it does not show all data it only show filtered data.
So how can I programmatically clear all filters so on click of search it will show all the values not filtered values.
I have not used default Filter Behavior.
Please check below code for reference
<af:table value="#{bindings.AfMyAccOrderStatusHistorySearchVO.rangeSet}"
var="row"
rows="#{bindings.AfMyAccOrderStatusHistorySearchVO.rangeSize}"
emptyText="#{bindings.AfMyAccOrderStatusHistorySearchVO.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.AfMyAccOrderStatusHistorySearchVO.rangeSize}"
rowBandingInterval="0" id="tblStatusHistoryList"
autoHeightRows="#{bindings.AfMyAccOrderStatusHistorySearchVO.rangeSize}"
rowSelection="single"
width="100%"
partialTriggers="::cb5 ::cb8 ::cb1 ::cb2"
filterModel="#{bindings.AfMyAccOrderStatusHistorySearchVO1Query.queryDescriptor}"
queryListener="#{bindings.AfMyAccOrderStatusHistorySearchVO1Query.processQuery}"
filterVisible="true" varStatus="vs"
binding="#{AfMyAccOrderStatusHistoryAction.orderStatusHistorySearchList}">
<af:column headerText="#{alfaprojectBundle['ordstatushistory.column.invoiceDate']}"
width="70"
sortProperty="invoiceDate"
sortable="true" filterable="true"
id="c7" filterFeatures="caseInsensitive">
<af:outputText value="#{row.invoiceDate}" id="ot16"/>
</af:column>
<af:column headerText="#{alfaprojectBundle['ordstatushistory.column.soldto']}"
width="100"
sortProperty="soldTo"
sortable="true" filterable="true"
id="c14" filterFeatures="caseInsensitive">
<af:outputText value="#{row.soldTo}"
visible="#{row.visibilityIsOrdrFirstItem}"
id="ot23"/>
</af:column>
So how to clear all filter values from java code.I can't get the example "Programmatically Manipulating a Table's QBE Filter Fields"
Where is it ?
https://smuenchadf.samplecode.oracle.com/samples/ClearTableColumnFilterFields.zip
Thks -
How to isolate the Sql Statement from Java Code
Hi
I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
Suppose the developer has these four Statements
Select ename,empno,sal,job from emp;
select empno,ename,mgr from emp;
select deptno,dname from dept;
select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
Can Anybody guide me how to write this Stored type of Store procedure.
Thankshttp://www.google.com/search?q=java+windows+registry
Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this. -
How to kill a system process from java code.
Hi,
i need to kill or remove windows system process like cmd.exe from java code.
like removing it from end process in task mgr.
i tried below code but its not removed.
is there a better way we can do this.
killing a system process from java code will create any issues?
public static void main(String[] args) throws Exception {
String[] cmd = { "cmd.exe" };
Process p = Runtime.getRuntime().exec(cmd);
p.destroy();
any suggestions or ideas are really appreciated.
thanks.Hi jtahlborn, mohan
yes the process is created from my java code.
in my code iam creating a process like below and if it is running for a long i need to kill it from java.
For that " Runtime.getRuntime().exec("taskkill /F /PID " + 7408); " is working fine.
7408 is my process id in taskmgr created from java and iam manually passing the PID it to kill it.
But i need to get the PID from java code.
Thanks for your suggestions.
Sample Code:
public static void main(String args[])
try {
Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start"});
Field f = process.getClass().getDeclaredField( "handle");
f.setAccessible( true);
long procHandle = f.getLong( process);
System.out.println( "prochandle: " + procHandle );
//Runtime.getRuntime().exec("taskkill /F /PID " + procHandle);
} catch( Exception e) {
e.printStackTrace(); -
Invoking Microsoft Word from Java code
I want to invoke Microsoft word from Java code. How can i do this plz ............... Help
do something along these lines.... here is an example with notepad
create a .bat file with the commmand in to run notepad for example
notpad c:\test.txtthis command calls notepad and passes it the argument C:\test.txt which is the file and it's location, that I want to open.
The Java program
import java.util.*;
import java.io.*;
public class Run
public static void main(String args[])
try
//the name of the batch file with your commands in
String command ="runprog.bat";
//get the runtime
Runtime rt = Runtime.getRuntime();
//run the bat file
Process proc = rt.exec(command);
//wait for the program to exit i.e notepad then get the return code
int exitVal = proc.waitFor();
//print out the exit value
System.out.println(2THe Process exit value is: " + exitVal);
catch(Throwable t)
t.printStackTrace();
}have a look at this
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
and this
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html -
Generate IDL from Java Code, Classes, UML, etc?
Hi,
is is possible to generate IDL code from Java Code, Classes, UML, ... using JDeveloper?
I know this is somewhat reverse engeneering, but it would speed up the migration of our existing Java project...
Thanks,
JohanHi,
is is possible to generate IDL code from Java Code, Classes, UML, ... using JDeveloper?
I know this is somewhat reverse engeneering, but it would speed up the migration of our existing Java project...Unfortunately it does not. The IDL to Java conversion is handled under the covers by the idl2java.exe included with the database. You might want to search on google for a IDL generator from java source.
java2iiop (another tool) just generates IIOP stubs from classes and interfaces, but I don't think it creates IDL.
Rob -
I am trying to create xml from raw data. It works well in the format builder but
when I instanciate the MFLObject and run convert to xml, the output only contains
wrappers for my first field described in the mfl. Are there any known issues
using this progmattic conversion to XML.
My mfl is the following:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE MessageFormat SYSTEM 'mfl.dtd'>
<!-- Enter description of the message format here. -->
<MessageFormat name='BossRecord' version='2.01'>
<FieldFormat name='Header' type='String' length='102' codepage='windows-1252'/>
<StructFormat name='TransactionControlRecord' delim='999'>
<FieldFormat name='TransactionTypeNumber' type='String' length='3' codepage='windows-1252'/>
<FieldFormat name='TransactionData' type='String' codepage='windows-1252'>
<LenField type='Numeric' length='4'/>
</FieldFormat>
</StructFormat>
<StructFormat name='Generic' repeat='*'>
<FieldFormat name='GenericTypeNumber' type='String' length='3' codepage='windows-1252'/>
<FieldFormat name='GenericData' type='String' codepage='windows-1252'>
<LenField type='Numeric' length='4'/>
</FieldFormat>
</StructFormat>
<FieldFormat name='IgnoreTheRest' type='Filler' optional='y' length='1' repeat='*'>
<!--
This field is useful for testing partially constructed formats. Adding
this field to the
end of a format will cause any leftover bytes on the end of a binary file to be
ignored when the data is converted to XML.
-->
</FieldFormat>
</MessageFormat>
Are there any issues with this that are easy to spot?
Here is some sample output:
_BossRecordDoc : <BossRecord>
<Header>0601uskyloupw7vu0 IBVRTR 000006RSQ1010246000000000000020436000001-01-01-00.00.00.00000000000100170</Header>
<Header>90100581D4EBC00AA3C18629ACA0004AC02E54BD289357023141961111F1111 99900207141D4EBC00AA3C18629ACA0004AC0</Header>
<Header>2E54BD2893570231RIBBONS & BUTTONS 9 00000000000010.50CAD00000000000000.5</Header>
<Header>0USD00000000000000.00USD00000000000077.00CAD 0CAUS00000000000000.91KGSA215D100CF3C18619AC</Header>
<Header>90004AC02E54B 01 0001-0</Header>
<Header>1-012003-04-072003-06-2501P/P03003984196000010100000000000000.00CAD 00
FR00000000000000</Header>
<Header>.0000000000000000000.00KGS00000000000000.00USD 00UPS T1</Header>
<Header>0001-01-010001-01-01 0 000000000000000.00000000000000000.00USD0</Header>
<Header>000000000000000.00 1 22222222222220 0100304061DC30500AA3C18629ACA</Header>
<Header>0004AC02E54B1D4EBC00AA3C18629ACA0004AC02E54B</Header>
<Header> 0010001-01-01 00000000000000.00USD00</Header>
<Header>000000000000.00CAD00000000000010.00CAD</Header>
<Header> 00000000000010.00CAD000000000000000010001-01-01K00404862A8D2C00AA3C186</Header>
<Header>29ACA0004AC02E54B1DC30500AA3C18629ACA0004AC02E54B001 PURPLE RIBBONS</Header>
It just keeps finding my first record instead of finding the remaing structure.
I appreciate any help.
Thanks,
MichaelOkay, I've got some coding off a site that looks like it will do what I want. It's quite a robust applications which will do more than I need but as long as it does at least what I want, i could care less. As it will extract files from the datastream for me, it is going to save them to disk.
I believe I have to specify a directory to save it to. I believe this is the line I'm going to modify, so assuming that's the case, how do I specify a directory here:
private File fileOutPutDirectory = null;
Do I have to use absolute paths or can I use relative. Also, what directory construct is expected by java? Anyone with an example of what urls are supposed to look like in this case?
Thanks,
destin
Maybe you are looking for
-
My voice memos will not transfer to my pc from my iphone ?
-
AO90 : Asset accounts determination
Hi Experts, We have two postable to GL depreciation area i.e. 01 and 25 and depr area, 01 is assigned to leading legder and deprceiation area 25 is assigned to non leading ledger. Depreciation area 25 is to post deprciation only. in account determin
-
Do all the HP Eprint printers work with ipad airplay?
I want to buy a new printer, it is a HP Photosmart Plus B210. It says that has eprint, will it work with the ipad2 airplay? thanks for th anwers
-
X-FI, No sound in rear and center speakers
Hi. I got a problem. I don't know what can I do more but after some combinations I can't get sound from rear speakers and center. I have X-Fi Gamer (SB0730) and it's connected to DTT2200. It's running on Windows 7 x32. Any Ideas what?can be the?probl
-
Tomcat Unloaded Application Automatically
Hi, I have problem with Tomcat 5. I have configure 2 ports in my tomcat. There are 3 applications sitting in the tomcat. Tomcat unloaded one of the application in the Tomcat automatically. The last request that was being processed by the application