Converting into XML without using DOM
Hi there,
I need to generate a XML file on the fly, given a HashMap. It will be used later to feed into XSLT parser.
Instead of using DOM parser which is memory intensive, I am generating the XML by appending the necessary into a String. For eg:
StringBuffer st = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append( "\n" );
sb.append("<"+ transaction.getCode() + ">");
...........................so on
I tried to gain resources in the book, but every example will actually use DOM to build a XML file.
I am just thinking what is the repercussion if i do not use DOM.
Could anyone please advice.
Thanks.
None really, if you don't need to walk the tree and have random access. Some find it hard to read / maintain, but I don't mind it. If you are just outputting to XSLT, what you are doing will work fine.
Similar Messages
-
Conversion of idoc into xml without XI
Hi everyone
i am working on EDI i want to know procedure to convert our idoc into XML without using XI. is it possible, if yes then plz reply me with procedure.
Thanks & Regards
VimarshHi Nicolai
Thanks for ur suggestion, i have one more doubt regarding this, i got this program to convert my records in XML but whatever output i m getting that comes in form of excell sheet, i am sending you that program which not working,
report zexternalfile .
tables : zzpublisher,
sscrfields.
data: it_publisher like standard table of zzpublisher,
wa_publisher like zzpublisher.
select * from zzpublisher into table it_publisher.
call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = 'C:\externalfiles\kamal.XLS'
FILETYPE = 'ASC'
APPEND = ' '
write_field_separator = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = it_publisher
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
if sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
IF YOU HAVE ANY OTHER OPTION THEN PLEASE SEND ME, I WILL BE VERY THANKFUL FOR YOU.
PLEASE SEND ME WHOLE PROCEDURE IF YOU CAN.
THANKS & REGARDS
VIMARSH -
Which are function modules used to convert into XML format in SAP 4.6c Ver
which are function modules used to convert into XML format in SAP 4.6c Ver
Hi,
check this program , I think this will help you
TYPE-POOLS: ixml.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
data : itab like catsdb occurs 100 with header line.
data : file_location type STRING.
data : file_name like sy-datum.
data : file_create type STRING.
file_name = sy-datum .
file_location = 'C:\xml\'.
concatenate file_location file_name into file_create.
concatenate file_create '.XML' into file_create.
DATA: l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
select * from catsdb into table itab.
append itab .
CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
I_XML_DOC_NAME =
IMPORTING
PE_BIN_FILESIZE = l_xml_size
TABLES
i_tab_sap_data = itab
CHANGING
I_TAB_CONVERTED_DATA = l_xml_table
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 24
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = file_create
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
write : 'INTERNAL TABLE DATA IS SUCCESSFULLY DOWNLOADED TO LOCATION', file_create .
Thanks. -
How to retrieve data from catsdb table and convert into xml using BAPI
How to retrieve data from catsdb table and convert into xml using BAPI
Points will be rewarded,
Thank you,
Regards,
Jagrut BharatKumar ShuklaHi,
This is not your requirment but u can try this :
CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
GRANT READ ON DIRECTORY text_file TO fah;
GRANT WRITE ON DIRECTORY text_file TO fah;
DROP TABLE load_a;
CREATE TABLE load_a
(a1 varchar2(20),
a2 varchar2(200))
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY text_file
ACCESS PARAMETERS
(FIELDS TERMINATED BY ','
LOCATION ('data.txt')
select * from load_a;
CREATE TABLE A AS select * from load_a;
SELECT * FROM A
Regards
Faheem Latif -
Idoc be converted into XML format
Hi,
Can idoc be converted into XML format? If yes guide me the path , how to do?
Thanks
Avi<b>Hi,
we can .
Follow the link
http://www.erpgenie.com/sap/sapedi/Conversion%20of%20IDOCs%20to%20XML%20format.pdf</b>
Thanks
Manju
<u><b>Don't repeat the Questions</b></u> -
Updating XML file using DOM parser
Hi,
Can someone help me, how to update following XML file using DOM parser.
The following is my XML file.
<students>
<student>
<id>1</id>
<name>abc</name>
</student>
<student>
<id>2</id>
<name>xyz</name>
</student>
<student>
<id>3</id>
<name/>
</student>
<student>
<id>4</id>
<name>ijk</name>
</student>
<student>
<id>5</id>
<name></name>
</student>
</students>Consider, I will input 2 fields, ie., id & name. For the matching Id, the name has to be updated.
Though, I have achieved this, but I am unable to update the value for 3rd record, & 5th record ie., id=3 & id=5. Since, these are blank.
Thanks.Some <name> elements have a child node which is a text node. From what you say it appears you know how to change those text nodes.
The other <name> elements don't have any child nodes. But you want one. This suggests to me that you need code that creates a text node and adds it to the <name> element as its child. -
Problem writing xml file using DOM
Hi,
I am trying to write a xml file using DOM. I am using xalan 2.5, xerces 1.4.4, jdk 1.3.1 in JRun 3 on windows.
The code where I get exception :
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult("pr.xml"));
I get the runtime error as follows:
javax.servlet.ServletException: null
java.lang.NoSuchMethodError
at org.apache.xml.utils.DOM2Helper.getNamespaceOfNodeDOM2Helper.java:342)
at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:387)
at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:202)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:343)
Thinking it is because of classpath, I placed xalan 2.5, xerces 1.4.4 jar files in jrun admin lib directory and in server lib directory as well. Still getting the same error.
Any suggestion?
Thanks in advancexalan is included in JRun 4. However JRun 3 does not.
However I tried with the same code in JRun3 in different system. The error is completely different. I understand this is because of different version of files. trying to solve ;)
Here my new exception
javax.servlet.ServletException: org/w3c/dom/ranges/DocumentRange
java.lang.NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
at com.cybell.appl.deliveryorder.cmd.CreateXMLDOFile.createFile(CreateXMLDOFile.java:73)
at com.cybell.appl.deliveryorder.cmd.CreateXMLDOFile.execute(CreateXMLDOFile.java:36)
at com.cybell.appl.framework.cmd.BaseCommand.start(BaseCommand.java:50)
at com.cybell.appl.framework.control.BaseController.service(BaseController.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:34)
at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75) -
Reading files and converting into xml structure
Hi,
In my application a client requests for the folder structure information to a server through RMI. The server needs to read files and folders on local machine and convert it into some structure (I am thinking of using xml) and send it back. For eg: I am planning to have Server send back something like:
<directory name = "parentdirectory">
<file name = "abc.jpg"/>
<file name = "def.bmp"/>
<directory" name = "subdirectory">
<file name = "hij.jpg"/>
<file name = "klm.bmp"/>
</directory>
</directory>
It is just the names of the files I am interested in and not the contents. Is this a good approach of sending back the data as a string containg xml definition. Is there any better appproach in terms of performance, memory etc? I am currently planning on using DOM for construction of this structure. Is there a source code for reading and converting the folder structure into xml. Just for your information, the clients gets this information and shows it as a tree structure on the GUI.
Thanks!!!!Is this a good approach of sending back the data as a string containg xml definition. It'll work.
An alternative, more direct approach is to build a memory representation and send this as argument/return value of an RMI call. You'd need to write classes MyDirectory and MyFile; MyFile has just a name; MyDirectory has a name and a collection of MyDirectory and one of MyFile. Make these classes implement Serializable and you can send them over RMI.
The effort to write those trivial classes would be less than to implement XML encoding/decoding, and also in terms of runtime performance and memory it will be hard to beat Java's serialization with anything XML-based. In this case I doubt performance/memory are relevant considerations though.
If for some reason I'd go for sending XML Strings anyway, I wouldn't do the encoding/decoding myself; I'd use XStream to convert Java classes to/from XML and still end up writing the above two classes and be done.
Sorry if you wanted a simple yes or no :-) -
How to remove element namespaces in XML file using DOM or SAX?
Hi Guys,
I developed a JAVA mapping in XI to add name spaces for XML file, after mapping,name spaces xmlns="http://www.mro.com/mx/integration" and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" were added correctly, but for some nodes, such as <Header> and <Content>, a name space xmlns="" was added automatically.Please check below files to compare.
It looks like be added automatically by XI. I didn't process anything for these nodes in JAVA program.
Now the issue is, how can I remove these redundant namespaces? Such as xmlns="".
Can I remove them using DOM or SAX in JAVA Mapping?
Thanks in advance.
====>Original XML file
<?xml version="1.0" encoding="UTF-8"?>
<LLYLPPInterface language="EN">
<Header>
<SenderID>GBIP</SenderID>
<CreationDateTime>2008-02-13T22:49:34-05:00</CreationDateTime>
<RecipientID/>
<MessageID/>
</Header>
<Content>
<LLY-LPP>
<INVOICE>
<INVOICELINE>
<PONUM>4780000008</PONUM>
<POLINENUM>1</POLINENUM>
<INVOICEQTY>1</INVOICEQTY>
<LOADEDCOST>68</LOADEDCOST>
</INVOICELINE>
</INVOICE>
</LLY-LPP>
</Content>
</LLYLPPInterface>
===>Target XML file after JAVA mapping
<?xml version="1.0" encoding="utf-8"?>
<LLYLPPInterface language="EN" xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header xmlns="">
<SenderID>GBIP</SenderID>
<CreationDateTime>2008-02-13T23:11:55-05:00</CreationDateTime>
<RecipientID/>
<MessageID/>
</Header>
<Content xmlns="">
<LLY-LPP>
<INVOICE>
<INVOICELINE>
<PONUM>4780000008</PONUM>
<POLINENUM>0</POLINENUM>
<INVOICEQTY>1</INVOICEQTY>
<LOADEDCOST>68</LOADEDCOST>
</INVOICELINE>
</INVOICE>
</LLY-LPP>
</Content>
</LLYLPPInterface>
Edited by: Eddie Zhang on Feb 14, 2008 9:22 AM
Edited by: Eddie Zhang on Feb 14, 2008 9:24 AMHi Milan,
Thanks for your replay.
Actually when I used module XMLAnonymizerBean to convert namespaces, the header of XML, such as <?xml version="1.0" encoding="UTF-8"?> was converted to format <?xml version='1.0' encoding='UTF-8'?>, quote was converted to single quote. Although I set parameter anonymizer.quote = ", it still didn't work, single quote appeared instead of quote.
I'm not sure why this happened. Can anyone help to clarify this?
Thanks
Edited by: Eddie Zhang on Feb 15, 2008 2:11 AM -
Store and load objects to XML files using DOM
Hello everybody,
a quick question for all of you.
I'm designing a desktop application which requires a lot of custom objects to be stored into XML files and later reloaded from them. I'm planning to use DOM, creating an interface like this:
public interface StorableAsDom
// Create an object from a DOM tree
static Object createFromDom(org.w3c.dom.Node root) throws InvalidDomException;
// Get the DOM tree for an object
org.w3c.dom.DocumentFragment getDomTree(org.w3c.dom.Document doc) throws DOMException;
Then, every class which needs to be saved should implement the above interface. This way everything works fine.
My question is: do you know any available java package which already provides similar functionalities?
I'd like not to reinvent the wheel if I can; time is always a critical factor.
Thanks in advance to all of you.
Cheers
marcocacoHi,
When I need object -xml binding, I usually have two methods -
one for reading & one for writing (the "VOs" below stands for "Value Objects" [getters/setters & empty constructor only]):
READ: loadXML (= XML2VOs)
1.XML2DOM - this method can be generic
2.DOM2VOs - populate your VOs from the DOM just obtained in 1.
WRITE: saveXML (=VOs2XML)
1.VOs2DOM - create a new DOM document from your VOs' fields.
2.DOM2XML - this method can be generic
It would be nice (but dificult & not very elegant) to make DOM2VOs & VOs2DOM generic. If such methods will be written, they should be combined with the XML2DOM & DOM2XML (resp.) & then you would have two generic methods XML2VOs & VOs2XML... (Alternativelly, you can get Sun's JAXB package which does object-xml binding but this is not part of the JDK 5)
If what I have outlined above sounds like what you want to do, let me know if you want more details (eg. how the DOM2VOs would be implemented etc)... -
Problem in parsing a xml string using dom parser
i want to parse a Xml String using a Dom parser......the parse function in dom parser takes only input stream as argument.......so i made the code as
InputStream inputstream = new StringBufferInputStream(XmlData) ;
InputSource inputSource = new InputSource(inputstream );
but saxexception is coming and also warning called
"java.io.StringBufferInputStream in java.io has been deprecated"
please help me.........i want to parse a Xml String using a Dom
parser......the parse function in dom parser takes
only input stream as argument.......This is not true of the DOM parser in Java 1.4. So you might want to get rid of your old parser and replace it by something more current. Or perhaps you are using 1.4 and you just didn't read all of the API docs. -
Delete elements from XML file using DOM and java
Hi
I want now is to remove element from my XML file
for example
i have following xml
<?xml version="1.0" encoding="UTF-8"?>
<printing>
<firstLineTexts>
<firstLineText />
<firstLineText>|line11</firstLineText>
<firstLineText>|line12</firstLineText>
</firstLineTexts>
</printing>how do i remove all elements fireLineText
my final output should be
<?xml version="1.0" encoding="UTF-8"?>
<printing>
<firstLineTexts>
</firstLineTexts>
</printing>How do i do it using DOM,
I can create instance of DOM and write it using TransformerFactory
AshishHi
I am trying the following code,
but it is not working
NodeList nScene = doc.getElementsByTagName("firstLineTexts");
NodeList nScene1 = nScene.item(0).getChildNodes();
for (int i = 0; i < nScene1.getLength(); i++)
Node n = nScene1.item(i);
nScene.item(0).removeChild(n);
} -
Can't convert stack XML file using report RPT_MOPZ_COPY_STACK for upgrade
Hello Colleagues/ SAP Experts,
Here is a background. 2 weeks ago, we have generated an XML stack file using MOPZ in solman 7.1 for the following systems (P6D which is DEV,
P6Q which is quality, P6R which is regression and P1P which is production). We were at our technical cutover rehearsal phase and the system that we were rehearsing was P6R. But AFTER our technical cutover, a new java component, which is seeburger as2 adapter, was installed in P1P, PRODUCTION. Thus, the landscape of P1P has changed as a new component was introduced and we believe that the generated XML file 2 weeks ago will no longer be valid for P1P. Instead of generating another xml file thru mopz for P1P, we would like to use report RPT_MOPZ_COPY_STACK_XML to convert the XML file OF P6R to map it toP1P. I have uploaded P6R XML and the target is P1P. So as you can see, P6R XML (source) --> P1P target.
Actions already done are the following:
1) Fulfilled and followed the resolution in note: 1711612
RPT_MOPZ_COPY_STACK_XML Report Troubleshooting
2) SAP-OSS is working in SM59
Basically, program RPT_MOPZ_COPY_STACK does not convert the Regression system's xml to the target, which is production. Kindly see attached screenshot. *the screenshot shows only 1 component in error but upon clicking the 'next difference' button, it will still show other components. I have checked my lmdb settings, will there be workaround for the issue?
Regards,
MeinardHello Divyanshu Srivastava / Reagan Benjamin ,
Thank you for your replies. Yes I noticed that a new higher patch for one java component was already present when I have regenerated recently for production using mopz. Anyways, SAP has returned a message wherein they edited the xml file themselves. Most of errors were eliminated only error was kernel versions was not matched. We need to upgrade kernel of our production and test if it works. Hopefully it will. Thanks though at first we did not edit the xml as according to one sap note I read it will not be supported by SAP. Closing this thread now -
Interactive-adobe form Converting into PDF without print dialog
Hi Friends,
I would like to convert Interactive - adobe form into PDF without print dialog.which adobe form interface type is Smart Forms-compatible Interface.I have tried for solution.but I could not succeeded.How can resolve the issue.please help me.
Thanks
Ramesh MHi Friends,
I would like to convert Interactive - adobe form into PDF without print dialog.which adobe form interface type is Smart Forms-compatible Interface.I have tried for solution.but I could not succeeded.How can resolve the issue.please help me.
Thanks
Ramesh M -
Hi all,
Can anyone tell how to convert the data in R3 to XML format.
thanx,
krishsame thread.
Re: function module to covert internal table to xml format
for more reference.
ABAP to XML with several internal tables
Re: Convert to XML format
Maybe you are looking for
-
Hi, I am using the java program to send the invoices to the different customers. I am able to send the email properly. There are some issues which I need to resolve. 1. Password protection with all the attachments with customer number. 2. Special Cha
-
Why is the FlashPaper in my website in front of my Navigation?
I loaded FlashPaper onto my site so people can view the newsletter right on their screen, my problem however, is that now you cannot get to the horizontal Spry navigation because the Flashpaper file covers it. How do I place the file at the back to
-
I have tried at least 10 times to do the latest Security Update (SecUpd2009-003Intel) on my MacBook Pro. It flew through with no problem on my Mac Mini, but keeps stopping at 99% writing on my MacBook Pro. I have run Disk Utilities, I have run DiskWa
-
Aperture previews in screen saver!
OK, this is just great (and maybe I'm the only one who didn't know this, but....) In Prefs->Screensaver, the Aperture library and projects show up, I think so long as there are previews in the project. Excellent, just excellent! Mark
-
Connecting an external hi-gain attenna to a WRT54G@
I have a WRT54G, is there any way for me to attach a hi-gain attenna? The router is very basic and does not show any external connectors. Is there an internal connection?