STORING DATA IN FILE IN XML FORMAT THROUGH JAVA ?
HOW TO STORE DATA IN FILE IN XML FORMAT THROUGH JAVA PROGRAM?
Have you looked into JAXB?
That is a new way of processing XML into Java classes or visa versa.
Otherwise, there are a lot of other XML related tools for Java in the -XML link on the left side of the page.
Similar Messages
-
How to store xml data into file in xml format through java program?
HI Friends,
Please let me know
How to store xml data into file in xml format through java program?
thanks......
can discuss further at messenger.....
Avanish Kumar Singh
Software Engineer,
Samsung India Development Center,
Bangalore--560001.
[email protected]Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
i got a piece of code from the net which allows me to parse th file:
import java.io.IOException;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.apache.xerces.parsers.SAXParser;
import java.lang.*;
public class MySaxParser extends DefaultHandler
private static int INDENT = 4;
private static String attList = "";
public static void main(String[] argv)
if (argv.length != 1)
System.out.println("Usage: java MySaxParser [URI]");
System.exit(0);
String uri = argv[0];
try
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
MySaxParser MySaxParserInstance = new MySaxParser();
parser.setContentHandler(MySaxParserInstance);
parser.parse(uri);
catch(IOException ioe)
ioe.printStackTrace();
catch(SAXException saxe)
saxe.printStackTrace();
private int idx = 0;
public void characters(char[] ch, int start, int length)
throws SAXException
String s = new String(ch, start, length);
if (ch[0] == '\n')
return;
System.out.println(getIndent() + " Value: " + s);
public void endDocument() throws SAXException
idx -= INDENT;
public void endElement(String uri, String localName, String qName) throws SAXException
if (!attList.equals(""))
System.out.println(getIndent() + " Attributes: " + attList);
attList = "";
System.out.println(getIndent() + "end document");
idx -= INDENT;
public void startDocument() throws SAXException
idx += INDENT;
public void startElement(String uri,
String localName,
String qName,
Attributes attributes) throws SAXException
idx += INDENT;
System.out.println('\n' + getIndent() + "start element: " + localName);
if (localName.compareTo("Machine") == 0)
System.out.println("YES");
if (attributes.getLength() > 0)
idx += INDENT;
for (int i = 0; i < attributes.getLength(); i++)
attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
if (i < (attributes.getLength() - 1))
attList = attList + ", ";
idx-= INDENT;
private String getIndent()
StringBuffer sb = new StringBuffer();
for (int i = 0; i < idx; i++)
sb.append(" ");
return sb.toString();
}// END PRGM
Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
The next step is to write the data to the DB.
Am sending an example of my file:
<Start>
<Machine>
<Hostname> IPCServer </Hostname>
<HostID> 80c04499 </HostID>
<MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
<CPU> UltraSPARC-IIi at 360 MHz </CPU>
<Memory> RAM : 512 MB </Memory>
<HostAdapter>
<HA> kern.info] </HA>
</HostAdapter>
<Harddisks>
<HD>
<HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
<HD2> ST38420A 8.2 GB </HD2>
</HD>
</Harddisks>
<GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
<NetworkType> hme0 : Fast-Ethernet </NetworkType>
<EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
<IPAddress> 149.51.23.140 </IPAddress>
</Machine>
</Start>
Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
Cal u tellme what to do!
Even better- do u have a piece of code that will help me understand and implement the database writing portion?
I badly need help here.
THANX -
Convert the flat file to xml format.
hi,
I need to write a interface program in the R/3 to pull the flat file data from the unix application server and do some manipulation and place back into the unix application server in XML format, From the unix box XML file taken by the XI server.
pls give me some idea to convert the flat file to XML format, through any function module or any other logic is there...
with regards,
Thambee.Hi Thambe
in addition to the above posts
Program to convert flat file to XML file.
please download tool from this link:
http://www.download.com/Stylus-Studio-2008-XML-Enterprise-Suite/3000-7241_4-10399885.html?part=dl-StylusStu&subj=dl&tag=button&cdlpid=10399885
how to use:
http://www.stylusstudio.com/learn_convert_to_xml.html
http://www.sap-img.com/abap/sample-xml-source-code-for-sap.htm
Flat file to XML
CONVERTION OF FLAT FILE TO XML : NO OUT PUT FOUND
Converting Idoc flat file representation to XML
how to convert flat file into IDOC-XML
Thanks
sandeep sharma
PS ; if helpful kindly reward points -
DME file in XML format in SAP 4.6C
Hi Experts,
For a Belgium client, I have a requirement to generate DME file in XML format for payments made to foreign and domestic vendors. I want to know the following,
1. Can DME file be generated in XML format using classic payment medium programs RFFOBE_E and RFFOBE_I.
2. If not why and what are the other options.
3. I also came to know that there is an options of using Payment medium workbench - through XML format trees BE_BEPDTA and BE_PIBDTA. But since we are in 4.6C, i am not able to create a payment format. Is there any support package or patch that is required.
4. I tried for SEPA_CT - again a XML format tree but was not very successful as that too was not available in SAP 4.6C. Is there any way that I can get this done in 4.6C - any support packages or patches available?
ThanksHi Kaylan,
could you please share that documentation with me too.
Thanks, Regards,
Alex Cardona -
Hello guys,
I am just wondering if i can write to a text file in xml format:
For example if i want to save the following:
Avisha 00/06/2000
The text file should show:
<record>
<name>Avisha</name>
<DOB00/06/200</DOB>
</record>
I think i probably needs to use some sort of XML schema, i never done it before and i would appriciate your help.
Thanks,corlettk wrote:
thomas.behr wrote:
Well, for simple cases, such as your example, just create an appropriate String and write that to your file.
For more complex cases, create a org.w3c.dom.Document (using DocumentBuilder and DocumentBuilderFactory), create the appropriate structure and use a javax.xml.transform.Transformer (created via TransformerFactory) to convert your Document from a DOMSource to StreamResult.I'm not a fan of the DOM solution... It's slow and very memory hungry... Goog for small datasets.
@OP If you can, I recommend using an XMLBinder (like [XML-Beans|http://xmlbeans.apache.org/] jusr for example) to both read and write all your XML.Errr, XMLBeans and the like will still be using DOM under the covers, so the memory issue is still as relevant as before. Happily, this turns out to be "not as much as you probably think" anyway. So the decision is a design one. Do you have schemas for this XML? You don't? Ah well, a binding framework's out of the question anyway. What are you doing with it? ("Processing it" isn't an answer). Where is it coming from? ("my codez" isn't an answer). What format need it be in? ("XML format" isn't an answer)
Building a DOM tree and serializing it isn't necessarily all that stupid an idea -
Convert gzip files into XML format
We have a requirement where we receive gzip files. These files are zipped file containing base64 binary format csv files. We would have to convert these files into XML format. Please let me know any of the following.
1. Is there any Xpath query or XSL function (somthing similar like doTranslateFromNative() ) to convert from gzip files to XML format.
2. If we need to unzip the zipfile outside fusion, then java code piece to unzip the gzip file. I guess after that we can use the usual doTranslateFromNative() function to translate to XML format, since after unzipping the gzip file, they are base64 binary formats.
Thanks in advance,
TomsThere is an option to do pre-processing and post processing of Files when using File adapter. You need to create a valve which will first do pre processing and send the output to FileAdapter.
You can get more information here:
http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm#CACDHGGG
under section: 4.2.14 Pre-Processing and Post-Processing of Files
Essentially you will use Java to unzip the file first and then the unzipped content will be passed to the adapter. -
Converting files into pdf format in java
Hi all,
How can we convert a file into PDF format in java?My application does the
file upload, and I need the files to be converted into PDF format.
The uploaded file can be of any type. How can I do this?
Please give me some help.
Thanks and regards,
Sandeep.>
How can we convert a file into PDF format in java?My application does the
file upload, and I need the files to be converted into PDF format.
The uploaded file can be of any type. ...>1) Write a class that will intelligently render a file of any type..
2) ... (well, do '1' first, then after getting your Nobel prize for AI, come back and we'll talk)
>
Please give me some help.>Please review your requirement.
BTW
- PDF sucks. It is designed for printing, and I (for one) don't want to kill more trees, and have no printer.
- This subject (convert file to PDF) has been discussed on the forums a bazillion times. Did you search the forums before asking your two (very closely related) questions? -
Why does photoshop elements 10 back up files in xml format
I am trying to backup my catalog including tags to my external hard drive. When I do the files are all in XML format. When I attempt to open using Photoshop
i get "wrong type of file" or they are just a lot of code. What is going on. Where are the pictures?I downloaded them into the same folder, and once that was done, I did as you said and opened PhotoshopElements_10_LS15.exe. It asked for my serial number and everything, seemed as though it was installing, and asked to restart in order to complete the process. I restarted the computer, and...I don't see Adobe Photoshop Elements 10 anywhere. There is a folder on my desktop that goes by the name of Photoshop Elements 10, but it only contains data files and things that I can't use. It's not the actual software....
What should I do? -
Log file in xml format: bad idea?
Hey
Im trying to write a class that will let other classes keep a log on whatever they want to. Whoever wants to write a message to a log file will call a function there, with the specified log name and the message, and my class will write it in xml format into the file.
Simple right? But here's the catch: in order to append a log into the file, I have to read it all first, then create the Element and add it to the root element. That meens that as the file grows, so will the time it takes to read it, and eventually log will take loads of time...
All this would not have happen otherwise, with simple text files, as all I have to do is to open the file for appending, which wouldn't take that much time.
So my questions are: Am I stupid to think this is possible with xml? Should I open the xml file as text file and then manipulate it? Are there any other possibilities?
Thanks for your help - UziWriting logs in an xml file is a very good idea and will later on provide you with a lot of flexibility to perform queries and how u want to display it.
Simple right? But here's the catch: in order to append
a log into the file, I have to read it all first, then
create the Element and add it to the root element.
That meens that as the file grows, so will the time it
takes to read it, and eventually log will take loads
of time...Why do you want to read the whole file for writing new elements. You dont have to do that. I have a simple idea for your problem.
e.g <logfile>
<log>
</log>
</logfile>
So now u want to add another log element. Use RandomAccessFile's length() method to find the size of the file.
Find the size of </logfile> e.g if it is sizeOfString.
Use RandonAccessFile's seek() method as follows
.......seek(lengthOfFile - sizeOfString);
This will move the pointer of the RandomAccessFile to this position. Next step is you can use writeBytes method to further write to this file.
That will increase the speed and performance and would give u great end results of an xml file. -
How to convert CSV/Text files to XML format
Hi,
I am trying to convert a .csv/.txt(Flat) file(s) to XML format. How can i achive this?
Ex: I want to convert this text file to XML.
Book# first name last name ID# ID1# F#
B99 FRISBY NASIER LUCJ A A 3127 1
B131 HAWKINS MICHAEL LUCJ A A 3129 2
B313 KING JOSHUA CUCJ I I-DORM 10
B307 GRAVES KIMBERLY NUCJ F F-DORM 24-FL
R469 HEATH DARRELL SUCJ A A 3132 1
R212 PEREZ DARRELL SUCJ A A 3133 2
R62 COFFEY GREGORY NUCJ HC H C 3112 3FLOOR
R215 BLACKWELL DEREK LUCJ OOW W 01 1 Could anyone please suggest me if we have any open source java api to acheive this?
Thanks,
Srikanth.Have a look at [http://servingxml.sourceforge.net/|http://servingxml.sourceforge.net/] or [http://www.talend.com/|http://www.talend.com/]
-
Create a file in fixed format through procedure
Hi Gurus !!,
Your help is greatly appreciated .
I know to create a procedure to genrate the file in a .csv format
But ,I have to create a procedure to generate a file in fixed format , So each field will have the length as per the length defied in the tables and with the page headers, etc
please help me here
beloW is the table structure of statae .
state :
NAME Not null VARCHAR2 (40 Byte)
STATE_CODE Not null VARCHAR2 (2 Byte)
CONTINENTAL_US_FLAG null VARCHAR2 (1 Byte)
sample data :
STATE_CODE
NAME
CONTINENTAL_US_FLAG
AI
ANGUILLA
AG
ANTIGUA AND BARBUDA
AW
ARUBA
N
BQ
BONAIRE,ST.EUSASIUS AND SABA
CW
CURACAO
Y
Data for the log and out files in the PROCESS_REFERENCE table
PROCESS_ID
PROCESS_NAME
FILE_IDENTIFIER
PATH_NAME
PROCESS_FILE_NAME
DATE_FORMAT_FOR_FILE_NAME
DEBUG_FLAG
369
FILE_STATE
LOG
/home/devtest/log/
<DATE>.FILE_STATE.LOG
YYYYMMDD
Y
340
FILE_STATE
OUT
/home/devtest/rpts/
<DATE>.FILE_STATE.OUT
YYYYMMDD
Y
This is the proc i created to generate .csv fiel which needs to be modidfied with fixed length formate as said above.
CREATE OR REPLACE PROCEDURE SAMPLE_FILE
AS
fLOG_FILE UTL_FILE.FILE_TYPE;
fRPT_FILE UTL_FILE.FILE_TYPE;
vLOGFILE_PATH PROD.PROCESS_REFERENCE.PATH_NAME%TYPE := NULL;
vLOGFILE_NAME PROD.PROCESS_REFERENCE.PROCESS_FILE_NAME%TYPE := NULL;
nLOGFILE_PROCESS_ID PROD.PROCESS_REFERENCE.PROCESS_ID%TYPE := NULL;
vRPTFILE_PATH PROD.PROCESS_REFERENCE.PATH_NAME%TYPE := NULL;
vRPTFILE_NAME PROD.PROCESS_REFERENCE.PROCESS_FILE_NAME%TYPE := NULL;
nRPTFILE_PROCESS_ID PROD.PROCESS_REFERENCE.PROCESS_ID%TYPE := NULL;
vDEBUG_FLAG PROD.PROCESS_REFERENCE.DEBUG_FLAG%TYPE := NULL;
nWRITE_COUNT NUMBER :=0;
vSYS_TIME VARCHAR2 ( 30 ):= NULL;
bLOG BOOLEAN :=FALSE;
PROCEDURE PROC_LOG ( LINE_IN IN VARCHAR2 )
IS
BEGIN
IF bLOG
THEN
vSYS_TIME :=TO_CHAR(SYSDATE, 'YYYYMMDD - HH24:MI:SS' );
UTL_FILE.PUT_LINE ( fLOG_FILE, 'Process Started on ' ||vSys_Time || ' - ' || LINE_IN );
UTL_FILE.FFLUSH ( fLOG_FILE );
bLOG :=TRUE;
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR IN LOG : ' || SUBSTR(SQLERRM,1,225));
RAISE;
END PROC_LOG;
BEGIN
SELECT PROCESS_ID, PATH_NAME, REPLACE(PROCESS_FILE_NAME,'<DATE>',
TO_CHAR(SYSDATE,DATE_FORMAT_FOR_FILE_NAME)) FILE_NAME, NVL(DEBUG_FLAG,'N') DEBUG_FLAG
INTO nLOGFILE_PROCESS_ID, vLOGFILE_PATH , vLOGFILE_NAME, vDEBUG_FLAG
FROM PROD.PROCESS_REFERENCE
WHERE PROCESS_NAME = 'FILE_STATE'
AND FILE_IDENTIFIER ='LOG' ;
IF vDEBUG_FLAG = 'Y' THEN
BEGIN
fLOG_FILE :=UTL_FILE.FOPEN(vLOGFILE_PATH,vLOGFILE_NAME,'W',32767);
bLOG := TRUE;
EXCEPTION
WHEN OTHERS THEN
bLOG := FALSE;
RAISE;
END;
END IF;
BEGIN
SELECT PROCESS_ID,PATH_NAME,
REPLACE(PROCESS_FILE_NAME,'<DATE>', TO_CHAR(SYSDATE,DATE_FORMAT_FOR_FILE_NAME)) FILE_NAME
INTO nRPTFILE_PROCESS_ID, vRPTFILE_PATH, vRPTFILE_NAME
FROM PROD.PROCESS_REFERENCE
WHERE PROCESS_NAME = 'FILE_STATE'
AND FILE_IDENTIFIER ='OUT' ;
PROC_LOG ('Opening File : '||vRPTFILE_NAME);
fRPT_FILE := UTL_FILE.FOPEN(vRPTFILE_PATH, vRPTFILE_NAME, 'W');
UTL_FILE.PUT_LINE(fRPT_FILE,'STATE CODE' || ','
|| 'NAME' || ','
|| 'CONTINENTAL_US_FLAG' );
EXCEPTION
WHEN NO_DATA_FOUND THEN
UTL_FILE.PUT_LINE(fLog_File,'ERROR in FILE OPEN : ' || SUBSTR(SQLERRM,1,1000));
RAISE;
END;
FOR CUR IN ( select state_code ,name, CONTINENTAL_US_FLAG from state ,COUNTRY
WHERE ALPHA_CODE =STATE_CODE)
LOOP
UTL_FILE.PUT_LINE(fRPT_FILE ,CUR.state_code || ' ,'
|| '''' ||CUR.CONTINENTAL_US_FLAG||''','
||'"'||CUR.name||'"');
nWRITE_COUNT :=nWRITE_COUNT+1;
END LOOP;
IF UTL_FILE.is_open (fRPT_FILE)
THEN
UTL_FILE.fclose (fRPT_FILE);
END IF;
PROC_LOG('---- PROCESS COMPLETED ---> ');
PROC_LOG('---TOTAL RECORDS WRITTEN ARE ---- : '|| nWRITE_COUNT );
IF UTL_FILE.IS_OPEN (fLOG_FILE)
THEN
UTL_FILE.FCLOSE (fLOG_FILE);
bLOG := FALSE;
END IF;
EXCEPTION
WHEN OTHERS
THEN
IF UTL_FILE.is_open (fLOG_FILE) THEN
PROC_LOG('ERROR IN MAIN !!' || SUBSTR(SQLERRM,1,250));
UTL_FILE.fclose (fLOG_FILE);
bLOG := FALSE;
ELSE
DBMS_OUTPUT.PUT_LINE('ERROR IN MAIN !!' || SUBSTR(SQLERRM,1,250));
END IF;
END SAMPLE_FILE ;Hi,
You can use RPAD to add spaces to the VARCHAR2 columns, like this:
UTL_FILE.PUT_LINE ( fRPT_FILE
, RPAD (CUR.state_code, 2) || ' ,''' ||
CUR.CONTINENTAL_US_FLAG || ''',"' ||
RPAD (CUR.name, 40) || '"'
Can the columns be NULL? If so, you may need
UTL_FILE.PUT_LINE ( fRPT_FILE
, RPAD (NVL (CUR.state_code, ' '), 2) || ' ,''' ||
NVL (CUR.CONTINENTAL_US_FLAG, ' ') || ''',"' ||
RPAD (NVL (CUR.name, ' '), 40) || '"'
since RPAD (str, len) returns NULL if str is NULL.
Lose those EXCEPTION sections. All they are doing is making it harder to find and fix errors. -
How to export report IN CSV format through JAVA.
how to export report in csv format.when try to export in csv format.its exporting into csv but report not containing column heading , report heading and it showing all the data in a single line.we have integrated the reports with java.
Use a Java API which can create PDF files based on some collection of plain vanilla Java objects (List, String, Number, etc).
Google can find them all. Just feed it with something like "Java PDF API" or so. A commonly used one is iText.
That said, when talking about this in JSP context, ensure that you do NOT write raw Java code in JSP files using scriptlets. Raw Java code belongs in Java classes. In such case you need a Servlet. In JSP just use taglibs and EL to interact with backend Java code and data. Scriptlets are discouraged since over a decade. -
Files creatd in Unix through java, URGENT
Hi,
While creating files in unix through Java, by default created files have only permission:
-rw-r--r--, actually I need full permissions(-rwxrwxrwx ) for the files created through java in unix. Any idea how can we do this?
Your help would be greately appriciated.
Thanks,
AnandI doubt that you will be able to get execute permissions set on normal files by setting the umask. You may have to use Runtime.exec() to invoke chmod, or call chmod via JNI if it is something you do often.
-
Data from table in xml Format and Inserting it into Table
Hi All
I have table where xml data is stored in long format with xml tag know i have read the entire xml xoulmn which is xml tag and insert it into diffrent table can any suggest me the code
Thanks & RegardsI believe you are on the wrong forum. You want the XML DB forum.
See:
XML DB -
Hi all,
If my application can not establish connection with the server it is storing 8000 xml files(one file per record).After connection with the server resumes it sends these xml files to server one by one and simultaneously deletes these files.
I want to know ,wheather it is a good design or not.My requirement is to store
8000 records at the local machine when server is down and then send these records one by one when server comes up.Please reply if anybody has something
in this respect.
With regards,
AjseIsn't it possible to store all 8000 records in one file?
Maybe you are looking for
-
How to move the Documents folder to another HD
I'll be installing a second HD by removing the DVD and want to move some folders to that drive. I would like to move Downloads and Documents folders. Thanks in advance, JoaoBra
-
Error 2927 when refreshing host cluster
We are running SCVMM 2012 R2 on Windows Server 2012 and it manages a 4 node 2012 Hyper-V cluster. I am receiving the following error when the job "Refresh host cluster" runs: Error (2927) A Hardware Management error has occurred trying to contact se
-
Goods Receipt through internal order with movement type 262
Dear Friends, some of our users making entries like the following 1. created Internal Order 2. Creating Reservation with movement type 262 ( which not issued material through movemnt type 261) 3. Stock updated i just want to confirm, we not issued
-
Transport the sender and Receiver Structures of Retraction
Hi, I would like to transport the sender structure which has been created in UPB_STRUCT and UPB_RULE. COuld some one tell me how to transport these objects.Points will be assigned. Thanks, Subha
-
Editing text is weird in dreamweaver!
i have been working on an apple for about a year now, and i had gotten used to using command+arrow keys instead of home and end like on a PC. this is the way i like it. in dreamweaver on a mac, they used home and end and the command+arrow keys thing