GUI to create all xml file combinations allowed by a Schema
Suppose I have an XML Schema and according to this Schema a total of six xml file configurations are legitimately possible.
1. Is there an easy way to create a Swing GUI that can be used to easily generate all six of these possible xml files?
...or...
2. Can anyone recommend specific tools that would be helpful in creating such a GUI.
I am familiar with tools to validate an xml file against a Schema but what tools are available to programmatically read a schema and extract all the possible legitimate combinations of the fields?
Hi,
What i need is the following:
I have some selects wich generates several XML files, but those files are plane, like this:
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<ROWSETTAG>
<ROWTAG>
<TX_COAPI>PES</TX_COAPI>
<TX_DNAPI>Consultas Pesetas</TX_DNAPI>
<TX_DEEUS>Datuak Pezetetan</YX_DEEUS>
<TX_DIREC>C:\TEST\</TX_DIREC>
<TX_ORDEN>11</TX_ORDEN>
</ROWAG>
Well, i need to apply an schema to each of that XML files, and the output of that process it should be a new XML file "formatted" or "transformed" ( i don't know what is the word) with the attributes,... that appears in a Schema file.
I don't know if this is possible, and how to do this, or maybe i should use a XSLT file...
i am newbie at this technology.
thx for your time!!!
Similar Messages
-
Creating an xml file from abap code
Hello All,
Please let me know which FM do I need to execute in order to create an XML file from my ABAP code ?
Thanks in advance,
Paul.This has been discussed before
XML files from ABAP programs -
URGENT -- Perofrmance issue while creating Huge XML file
All XML Experts Please Help....Thanks a lot in Advance
We are trying to create a XML file for a huge table.. 5 million rows and the performance is ver very bad.. Can some body help by giving me an idea what what my best approch could be... or what am I doing wrong in in the code below
CREATE OR REPLACE PROCEDURE Sales_1_Generate_Xml IS
temp_clob CLOB;
temp_buffer VARCHAR2(1);
amount BINARY_INTEGER := 1;
position INTEGER := 1;
filehandle utl_file.file_type;
error_number NUMBER;
error_message VARCHAR2(100);
length_count INTEGER;
qryctx dbms_xmlgen.ctxhandle;
BEGIN
qryctx := dbms_xmlgen.newcontext('select /* INDEX UF_SALES(UF_SALES_IX16) */
TRANSACTION_NUMBER "Transaction_Number",
TRANSACTION_TYPE_ID "Transaction_Type_ID",
PROCESS_FISCAL_DATE_ID "Process_Fiscal_Date_ID",
INVOICE_FISCAL_DATE_ID "Invoice_Fiscal_Date_ID",
ORDER_FISCAL_DATE_ID "Order_Fiscal_Date_ID",
PROCESS_CALENDAR_DATE_ID "Process_Calendar_Date_ID",
INVOICE_CALENDAR_DATE_ID "Invoice_Calendar_Date_ID",
ORDER_CALENDAR_DATE_ID "Order_Calendar_Date_ID",
CURRENT_TM_ID "Current_TM_ID",
CUSTOMER_ID "Customer_ID",
CUSTOMER_TYPE_ID "Customer_Type_ID",
CUSTOMER_LEVEL_ID "Customer_Level_ID",
ACCOUNT_TYPE_ID "Account_Type_ID",
TRADE_CLASS_ID "Trade_Class_ID",
DISTRIBUTOR_ID "Distributor_ID",
PRODUCT_ID "Product_ID",
ORDERED_PRODUCT_ID "Ordered_Product_ID",
BRAND_TYPE_ID "Brand_Type_ID",
LABEL_TYPE_ID "Label_Type_ID",
BRAND_LABEL_ID "Brand_Label_ID",
PRICED_BY_ID "Priced_By_ID",
SALES_UOM_ID "Sales_UOM_ID",
PURCHASING_UOM_ID "Purchasing_UOM_ID",
PRICING_UOM_ID "Pricing_UOM_ID",
NET_COST "Net_Cost",
NPA_S "NPA_S",
CMA_S "CMA_S",
NOT_S "NOT_S",
TOTAL_NATIONAL_ALLOWANCE_S "Total_National_Allowance_S",
LPA_S "LPA_S",
LMA_S "LMA_S",
LOT_S "LOT_S",
TOTAL_LOCAL_ALLOWANCE_S "Total_Local_Allowance_S",
TOTAL_ALLOWANCES_S "Total_Allowances_S",
LPC "LPC",
LPC_EXTENDED "LPC_Extended",
LPF "LPF",
LPF_EXTENDED "LPF_Extended",
TRUE_COST "True_Cost",
CDE "CDE",
LPP "LPP",
SURCHARGE "Surcharge",
COMBINED_SURCHARGE "Combined_Surcharge",
TOTAL_SURCHARGES "Total_Surcharges",
MARKET_COST "Market_Cost",
INSIDE_PAD "Inside_Pad",
SALES_REP_COST "Sales_Rep_Cost",
SALES_REP_MARGIN "Sales_Rep_Margin",
SALES_PRICE "Sales_Price",
SALES_TRUE_MARGIN "Sales_True_Margin",
NVD "NVD",
LVD "LVD",
NID "NID",
LID "LID",
TOTAL_VD "Total_VD",
TOTAL_ID "Total_ID",
TOTAL_DEVIATIONS "Total_Deviations",
GP1 "GP1",
GP2 "GP2",
DEVIATED_COST "Deviated_Cost",
ACTUAL_COST "Actual_Cost",
SALES_TAX "Sales_Tax",
QUANTITY_ORDERED "Quantity_Ordered",
QUANTITY_SHIPPED "Quantity_Shipped",
QUANTITY_DEVIATED "Quantity_Deviated",
QUANTITY_SUBBED "Quantity_Subbed",
UNITS_ORDERED "Units_Ordered",
EACHES_ORDERED "Eaches_Ordered",
EACH_CONVERSION_FACTOR "Each_Conversion_Factor",
UNITS_SHIPPED "Units_Shipped",
EACHES_SHIPPED "Eaches_Shipped",
SHIP_WEIGHT "Ship_Weight",
ACTUAL_GP_DLR "Actual_GP_Dlr",
TRUE_GP_DLR "True_GP_Dlr",
LANDED_GP_DLR "Landed_GP_Dlr",
LANDED_ACTUAL_GP_DLR "Landed_Actual_GP_Dlr",
INVOICE_GP_DLR "Invoice_GP_Dlr",
INVOICE_ACTUAL_GP_DLR "Invoice_Actual_GP_Dlr",
ADJUSTED_ACTUAL_GP_DLR "Adjusted_Actual_GP_Dlr",
EB_S "EB_S",
MB_S "MB_S",
ACTUAL_TM_ID "Actual_TM_ID",
ACTUAL_TM_NAME "Actual_TM_Name",
ACTUAL_DSM_ID "Actual_DSM_ID",
ACTUAL_DSM_NAME "Actual_DSM_Name",
INVOICE_NUMBER "Invoice_Number ",
CONTRACT_NUMBER "Contract_Number",
CUSTOMER_NUMBER "Customer_Number",
CUSTOMER "Customer",
PRODUCT_NUMBER "Product_Number",
MASTER_DISTRIBUTOR_ID "Master_Distributor_ID",
ORDERED_PRODUCT_NUMBER "Ordered_Product_Number",
NATIVE_PRODUCT_STATUS "Native_Product_Status",
NATIVE_PRICED_BY_INDICATOR "Native_Priced_By_Indicator",
EXTRACTION_TIME "Extraction_Time"
from uf_sales where distributor_id in (''5139'',
''5140'',
''5145'',
''5150'',
''5160'',
''5175'',
''5180'',
''5210'',
''5220'',
''5230'')
DBMS_XMLGen.setRowTag(qryctx,'Sales_Record');
DBMS_XMLGen.setRowSetTag(qryctx,'Sales_Set');
temp_clob:=dbms_xmlgen.getxml(qryctx);
length_count := dbms_lob.getlength(temp_clob);
dbms_output.put_line('Internal LOB size is: ' || length_count);
filehandle := utl_file.fopen('DATA_EXTRACT','Sales_1.xml','Wb',32767);
WHILE length_count <> 0 LOOP
dbms_lob.read (temp_clob, amount, position, temp_buffer);
--utl_file.put (filehandle, temp_buffer);
utl_file.put_raw(filehandle, utl_raw.cast_to_raw(temp_buffer));
position := position + 1;
length_count := length_count - 1;
temp_buffer := null;
END LOOP;
dbms_output.put_line('Exit the loop');
utl_file.fclose(filehandle);
DBMS_XMLGen.closeContext(qryctx);
dbms_output.put_line('Close the file');
EXCEPTION
WHEN OTHERS THEN
BEGIN
error_number := sqlcode;
error_message := substr(sqlerrm ,1 ,100);
dbms_output.put_line('Error #: ' || error_number);
dbms_output.put_line('Error Message: ' || error_message);
utl_file.fclose_all;
END;
END;
/OK, so you are writing the file with UTL_FILE. How long is the whole process taking. Have you timed the time taken to generate the temp_clob with the result Vs the time to write the output to a file.
-
Creating an xml file from recordset
Hi...
XML newbie here - so.
Is it possible to create and xml file from a recordset?
I need to create a datafeed of our e-commerce products.
Also, some of the db data contains HTML Code (product
description field),
how will this effect the xml file?
Another problem is that my xml file needs to contain url's
for the products
and product images. My ASP pages contain these URL in hard
code and then
pull the actual file names from the db
Hope that makes some sense
Thanks for any help
AndyHi David
Thanks for your help.
I think it will have to be option 1 as i am using Access DB.
I don't know how to go about it but will serach good old
Google.
Here is my recordset below, that pulls the required data from
Access.
The product and product image URL's need to be in the xml
file but only the
product image name and product id are in the database, e.g
image name
(imagename.jpg) productid (21)
The actual URL's are hardcoded in my ASP pages, e.g <img
src="products/medium/<%=(RSDetails.Fields.Item("Image").Value)%>"
Not sure if this makes things any clearer :-|
Thanks Again
Andy
<%
Dim RSdatafeed
Dim RSdatafeed_numRows
Set RSdatafeed = Server.CreateObject("ADODB.Recordset")
RSdatafeed.ActiveConnection = MM_shoppingcart_STRING
RSdatafeed.Source = "SELECT Products.Product,
Products.Description,
Products.Image, Products.image2, Products.ListPrice,
Products.Price,
Products.xml_feed, Manufacturers.Manufacturer,
Shipping.ShippingCost FROM
Shipping, Products INNER JOIN Manufacturers ON
Products.ManufacturerID =
Manufacturers.ManufacturerID WHERE
(((Products.xml_feed)=No));"
RSdatafeed.CursorType = 0
RSdatafeed.CursorLocation = 2
RSdatafeed.LockType = 1
RSdatafeed.Open()
RSdatafeed_numRows = 0
%>
"DEPearson" <[email protected]> wrote in
message
news:[email protected]...
> Andy,
>
> There are two ways you can create a xml file from a
recordset
>
> 1. Is to code it using Server.CreateObject(XMLDOM)
> 2. If you are using SQL server 2005, just request the RS
returns as XML
> data. using FOR XML AUTO after the where cause ( the
best way with 2005
> and
> higher sql server)
>
> The db data containing HTML code should not effect your
xml file, unless
> it
> is bad markup. You could wrap the data with
<![CDATA[the data or html
> markup, or javascript]]>
>
> If the url is a recordset field, then it will return
with the xml data.
> If
> not you can create a storage procedure that will build
your URL from the
> data
> in the database.
>
> It is best to use storage procedure (SP )for security
reason when pulling
> data
> from a MS Sql server, make all calls to the database in
a SP. Also be sure
> to
> validate the values in the querystrings before accepting
them, check for
> hack
> code.
>
> David
> -
How I can create a XML file from java Aplication
How I can create a XML file from java Aplication
whith have a the following structure
<users>
<user>
<login>anyName</login>
<password>xxxx</password>
</user>
</users>
the password label must be encripted
accept any suggestionLet us assume you have all the data from the jsp form in an java bean object..
Now you want a xml file. This can be acheived in 2 ways
1. Write it into a file using java.io classes. Say you have a class with name
write("<name>"+obj.getName+</name>);
bingo you have a flat file with the xml
2. Use data binding to do the trick
will recommend JiBx and Castor for the 2nd option
Regards,
Rajagopal -
How to create an XML file from scratch ?
Hi all,
I'm afraid that I will seem dummy, but I think I really misunderstand something or I'm trying to do something that is not possible...
I would like to create a XML file containing the following:<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="pl.xsl"?>
<!DOCTYPE playlist SYSTEM "pl.dtd">
<playlist id="2">
</playlist>I really need to have both the stylesheet and the DOCTYPE declarations... Does anyone know if this is possible ?
To create the XML Document, I am using the DocumentBuilder object from javax.xml package (jaxp-1.2-ea2). I think this, at least, is correct.
To print out the XML document I have tried to use :
- the Transformer from javax.xml package (jaxp-1.2-ea2) but I could obtain only the DOCTYPE declaration.
- the Serializer from Xerces parser (version 2.0.1) to print out the Document I am creating with the jaxp, but I was able only to obtain the stylesheet declaration...
So far I have just understand that there is a difference between Serializer and Transformer (one is serializing, and the other is transforming ;-)), but I couldn't figure out which one would be suitable to produce the XML file above...
I would really appreciate if one could help me with that ;-)
Thanks,
KarauCould send me an example ?
For the moment I am using Transformer in that way:
TransformerFactory tfactory = TransformerFactory.newInstance();
try {
Transformer transformer = tfactory.newTransformer();
DOMSource source = new DOMSource(playlistDoc.getDocumentElement());
StreamResult res = new StreamResult(new File(path));
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PL_DTD);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, res);
catch (TransformerConfigurationException tce) {
throw tce;
catch (TransformerException te) {
throw te;
} -
How to create new XML file using retreived XML content by using SAX API?
hi all,
* How to create new XML file using retreived XML content by using SAX ?
* I have tried my level best, but output is coming invalid format, my code is follows,
XMLFileParser.java class :-
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
public class PdfParser extends XMLFilterImpl {
private TransformerHandler handler;
Document meta_data;
private StringWriter meta_data_text = new StringWriter();
public void startDocument() throws SAXException {
void startValidation() throws SAXException {
StreamResult streamResult = new StreamResult(meta_data_text);
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try
handler = factory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
handler.setResult(streamResult);
handler.startDocument();
catch (TransformerConfigurationException tce)
System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
super.startDocument();
public void startElement(String namespaceURI, String localName,
String qualifiedName, Attributes atts) throws SAXException {
handler.startElement(namespaceURI, localName, qualifiedName, atts);
super.startElement(namespaceURI, localName, qualifiedName, atts);
public void characters(char[] text, int start, int length)
throws SAXException {
handler.characters(text, start, length);
super.characters(text, start, length);
public void endElement(String namespaceURI, String localName,
String qualifiedName) throws SAXException {
super.endElement("", localName, qualifiedName);
handler.endElement("", localName, qualifiedName);
public void endDocument() throws SAXException {
void endValidation() throws SAXException {
handler.endDocument();
try {
TransformerFactory transfactory = TransformerFactory.newInstance();
Transformer trans = transfactory.newTransformer();
SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
DOMResult dom_result = new DOMResult();
trans.transform(sax_source, dom_result);
meta_data = (Document) dom_result.getNode();
System.out.println(meta_data_text);
catch (TransformerConfigurationException tce) {
System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
catch (TransformerException te) {
System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
} CreateXMLFile.java class :-
Sax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
* In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
is not an XML type text, it just an Normal text Why that ?
* Please help me what is the problem in my code?
Cheers,
JavaImranSax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
</code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
<code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
* I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
* I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
Thanks,
JavaImran{code} -
Create an XML File in Application server
Hello,
I have a requirement to create an XML File as Local File and as server File. For the local File it works fine and i got a Local XML File.
My problem is for the Server File.I found a solution in internet to convert in binary.But i don't get in the server File created the XML structure.
Here is My code for the unix server File
DATA ex_tab TYPE TABLE OF x255.
data: wa_tab type x255.
data: lv_line(255) type c.
**-- carica tabella gt_file
PERFORM CARICA_TAB_FILE.
LOOP AT GT_FILE.
MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.
APPEND WA_SOURCE TO GT_SOURCE.
CLEAR WA_SOURCE.
ENDLOOP.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION ZMESMO052_XML
SOURCE MATERIAL_DATA = GT_SOURCE[]
RESULT XML XML_RESULT .
CATCH CX_ROOT INTO GS_RIF_EX.
GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).
MESSAGE GS_VAR_TEXT TYPE 'E'.
ENDTRY.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = XML_RESULT
TABLES
binary_tab = ex_tab.
CONCATENATE P_FILE '.xml' INTO P_FILE.
CONDENSE P_FILE.
TRANSLATE P_FILE TO LOWER CASE.
OPEN DATASET P_FILE FOR OUTPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
MESSAGE E000(ZF) WITH ' Error opening File' P_FILE.
ENDIF.
loop at ex_tab into wa_tab.
move wa_tab to lv_line.
transfer lv_line to p_file.
endloop.
close dataset p_file.
And i Got a file like this
Any solution pleaseI Found the solution,
DATA EX_TAB TYPE TABLE OF X255.
DATA: WA_TAB TYPE X255.
DATA: LV_LINE(255) TYPE C.
DATA: L_CONVIN TYPE REF TO CL_ABAP_CONV_IN_CE.
DATA: L_HTML TYPE STRING.
DATA: L_VALUE TYPE STRING.
DATA: L_MSGSTR TYPE STRING.
DATA: FILENAME TYPE STRING.
**-- carica tabella gt_file
PERFORM CARICA_TAB_FILE.
LOOP AT GT_FILE.
MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.
APPEND WA_SOURCE TO GT_SOURCE.
CLEAR WA_SOURCE.
ENDLOOP.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION ZMESMO052_XML
SOURCE MATERIAL_DATA = GT_SOURCE[]
RESULT XML XML_RESULT .
CATCH CX_ROOT INTO GS_RIF_EX.
GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).
MESSAGE GS_VAR_TEXT TYPE 'E'.
ENDTRY.
TRY.
CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
EXPORTING
ENCODING = 'UTF-8'
INPUT = XML_RESULT
RECEIVING
CONV = L_CONVIN.
CALL METHOD L_CONVIN->READ
IMPORTING
DATA = L_HTML.
CATCH CX_ROOT.
L_MSGSTR = 'Conversion error'.
ENDTRY.
SEARCH L_HTML FOR '><'.
CLEAR L_VALUE.
L_VALUE = CL_ABAP_CHAR_UTILITIES=>NEWLINE.
CONCATENATE '>' L_VALUE '<' INTO L_VALUE.
IF SY-SUBRC = 0.
REPLACE ALL OCCURRENCES OF '><' IN L_HTML WITH L_VALUE IN
CHARACTER MODE.
ENDIF.
CONCATENATE P_FILE '.xml' INTO P_FILE.
CONDENSE P_FILE.
TRANSLATE P_FILE TO LOWER CASE.
FILENAME = P_FILE.
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE
WITH UNIX LINEFEED.
TRANSFER L_HTML TO FILENAME.
CLOSE DATASET FILENAME. -
Using jsp creating the xml file on the browser
Hi All,
My problem is i have jsp page by which i am getting the data from data base, by using the database table i want to create the xml file
can anybody help in this issueOh, "the thing". Let me see if I can find that code for you ...
-
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. -
Need help Take out the null values from the ResultSet and Create a XML file
hi,
I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
null values to XML File. When i run the program it works alright and adds the null and not null values to
the file. But when i pass the boolean value to take out the null values it would not take it out and adds
the null and not null values.
Please look at the code i am posing. I am showing step by step where its not adding the null values.
Any help is always appreciated.
Thanks in advance.
============================================================================
Frame1 Class
============
public class Frame1 extends JFrame{
private JPanel contentPane;
private XQuery xQuery1 = new XQuery();
private XYLayout xYLayout1 = new XYLayout();
public Document doc;
private JButton jButton2 = new JButton();
private Connection con;
private Statement stmt;
private ResultSetToXML rstx;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
xQuery1.setSql("");
xQuery1.setUrl("jdbc:odbc:SCANODBC");
xQuery1.setUserName("SYSDBA");
xQuery1.setPassword("masterkey");
xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
jButton2.setText("Get XML from DB");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException ex) {
System.err.print("ClassNotFoundException: ");
System.err.println(ex.getMessage());
try {
con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
stmt = con.createStatement();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
void jButton2_actionPerformed(ActionEvent e) {
try{
OutputStream out;
XMLOutputter outputter;
Element root;
org.jdom.Document doc;
root = new Element("PINFO");
String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
ResultSet rs = stmt.executeQuery(query);
/*===========This is where i am passing the ResultSet and boolean=======
===========value to either add the null or not null values in the file======*/
rstx = new ResultSetToXML(rs,true);
} //end of try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
======================================================================================
ResultSetToXML class
====================
public class ResultSetToXML {
private OutputStream out;
private Element root;
private XMLOutputter outputter;
private Document doc;
// Constructor
public ResultSetToXML(ResultSet rs, boolean checkifnull){
try{
String tagname="";
String tagvalue="";
root = new Element("pinfo");
while (rs.next()){
Element users = new Element("Record");
for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
tagname= rs.getMetaData().getColumnName(i);
tagvalue=rs.getString(i);
System.out.println(tagname);
System.out.println(tagvalue);
/*============if the boolean value is false it adds the null and not
null value to the file =====================*/
/*============else it checks if the value is null or the length is
less than 0 and does the else clause in the if(checkifnull)===*/
if(checkifnull){
if((tagvalue == null) || tagvalue.length() < 0 ){
users.addContent((new Element(tagname).setText(tagvalue)));
else{
users.addContent((new Element(tagname).setText(tagvalue)));
else{
users.addContent((new Element(tagname).setText(tagvalue)));
root.addContent(users);
out=new FileOutputStream("c:/XMLFile.xml");
doc = new Document(root);
outputter = new XMLOutputter();
outputter.output(doc,out);
catch(IOException ioe){
System.out.println(ioe);
catch(SQLException sqle){Can someone please help me with this problem
Thanks. -
How to make a bean create an xml file..
How does one create an xml file from a bean?
If anyone have the answer, or some sample code I would really apprecciate it!!!
In advance thanx a lot!!!just "wrap" this up in a bean.
import java.io.*;
import org.jdom.*;
import org.jdom.output.*;
/** Make up and write an XML document, using JDOM
* @author Ian Darwin, [email protected]
* @version $Id: DocWriteJDOM.java,v 1.2 2001/11/21 23:08:17 ian Exp $
public class DocWriteJDOM {
public static void main(String[] av) throws Exception {
DocWriteJDOM dw = new DocWriteJDOM();
Document doc = dw.makeDoc();
// Create an output formatter, and have it write the doc.
new XMLOutputter().output(doc, System.out);
/** Generate the XML document */
protected Document makeDoc() throws Exception {
Document doc = new Document(new Element("Poem"));
doc.getRootElement().
addContent(new Element("Stanza").
addContent(new Element("Line").
setText("Once, upon a midnight dreary")).
addContent(new Element("Line").
setText("While I pondered, weak and weary")));
return doc; -
Create a xml file from an internal table: CALL TRANSFORMATION
Hello gurus,
I want to create a xml file using data from scustom table. I will create an internal table and will select some records to it.
I searched the forum and i discovered the call transformation, but when i execute the example program at the CALL TRANSFORMATION shows a dump screen.
How we create a xml file from internal table??
Please help me. I will mark the useful answers.I'm using if_ixml class to create xml documents
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: o_ixml TYPE REF TO if_ixml,
o_document TYPE REF TO if_ixml_document,
o_element TYPE REF TO if_ixml_element,
o_streamfactory TYPE REF TO if_ixml_stream_factory,
o_ostream TYPE REF TO if_ixml_ostream,
o_renderer TYPE REF TO if_ixml_renderer.
DATA: t_xml_table TYPE TABLE OF xml_line,
v_xml_size TYPE i.
o_ixml = cl_ixml=>create( ).
o_document = o_ixml->create_document( ).
* The o_document have a set of methods to add elements, attributes, etc.
o_element = o_document->create_simple_element(
name = 'RootNode'
value = 'some text'
parent = o_document ).
o_streamfactory = o_ixml->create_stream_factory( ).
o_ostream = o_streamfactory->create_ostream_itable( table = t_xml_table ).
o_renderer = o_ixml->create_renderer( ostream = o_ostream document = o_document ).
o_renderer->render( ).
v_xml_size = o_ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = v_xml_size
filename = 'C:a.xml'
filetype = 'BIN'
CHANGING
data_tab = t_xml_table. -
Creating an xml file from java.
I trying to create an xml file using a java program. I just wondering what is the best way to go about it and what should i use jdom ,xerces sax etc.
Use JAXP+SAX.
Here an example:import java.io.*;
// SAX classes.
import org.xml.sax.*;
import org.xml.sax.helpers.*;
//JAXP 1.1
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;
// PrintWriter from a Servlet
PrintWriter out = response.getWriter();
StreamResult streamResult = new StreamResult(out);
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
// SAX2.0 ContentHandler.
TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"users.dtd");
serializer.setOutputProperty(OutputKeys.INDENT,"yes");
hd.setResult(streamResult);
hd.startDocument();
AttributesImpl atts = new AttributesImpl();
// USERS tag.
hd.startElement("","","USERS",atts);
// USER tags.
String[] id = {"PWD122","MX787","A4Q45"};
String[] type = {"customer","manager","employee"};
String[] desc = {"Tim@Home","Jack&Moud","John D'o�"};
for (int i=0;i<id.length;i++)
atts.clear();
atts.addAttribute("","","ID","CDATA",id);
atts.addAttribute("","","TYPE","CDATA",type[i]);
hd.startElement("","","USER",atts);
hd.characters(desc[i].toCharArray(),0,desc[i].length());
hd.endElement("","","USER");
hd.endElement("","","USERS");
hd.endDocument();
[i]This xml generation program might be the best solution because it uses JAXP 1.1 so it will work under JDK 1.4 or JDK 1.2/1.3 with XALAN2 library (or any XML library JAXP 1.1 compliant). It's also memory-friendly because it doesn't need DOM.
See http://www.javazoom.net/services/newsletter/xmlgeneration.html
Hope That Helps -
I'm a new user of XML. I've a very important question:
Is it possible create an XML file using some java package? If yes what package i must use? JDOM is the right product?
ThanksYes, JDOM is the right choice for 99% of your work.
DOM is too difficult to use.
That is the reason why JDOM has been developped.
Maybe you are looking for
-
My MacBook will no longer connect to my wireless printer.
My MacBook (circa 2010 - it's not a MacBook Pro) stopped connecting wirelessly to my HP printer (3050 J610). I get a message, "Printer is offline." The printer is on and I have no trouble printing from my iMac. I appreciate any advice/insights. Thank
-
We have a workflow which triggers on PO creation/change , and sends a mail to the PR creator for which the PO has been created . We have a new requirement to add an attachment which contains the PO created in PDF form , in the mail sent to the PR. Ca
-
Application containing only resources and no run target
HI Gentlemen, I have a set of web applications with XSQL sheets. These reference different subsets of stylesheets, and XML files as lookups from a large pool. Now it happens several times that a stylesheet or XML file is referenced in many different
-
No internet access after Snow upgrade
Was very upset yesterday after upgrading my 13" Macbook Pro to Snow Leopard only to find out I couldn't get online via ethernet or Airport. Went through all kinds of troubleshooting and just got off a 90 minute long convo with an Apple phone genius.
-
I'm trying to export a WMV from Final Cut, however it wont transcode the whole timeline. I tried M-Peg streamclip as well and no luck. Any suggestions would be greatly appreciated.