DOM XML parser program
Hi,
I am trying to write a sample program using DOM xml parser in java to read the values in a XML file.
please suggest me what are all the things I have to do for that.
I know Java and XML. I want to know how to access values from XML file in java.
Thanks
Selvakumar
Study up on the javax.xml.parsers API here at Sun. Next, download Xerces from Apache (xml.apache.org). Finally, take a tutorial.
- Saish
Similar Messages
-
Hey, I apologize for the newbie question but I suppose this is as good a place as any for it. I'm in desperate need of a DOM XML parser and have decided upon the Apache parser, "Xerces," featured here. My problem is this, every time I make a move towards installing it, I get all mixed up at the mention of my "Apache, ant and forrest" installations that I am apparently supposed to have in order for this library to work. My question is, is this library only for use in web-based applications and thus requires Apache in order to run? I ask because the application I'm working on is simply for desktop usage and the users it will be distributed to will not have Apache installations. If somebody could help me out with a quick little walk-through on the installation of this library it would be IMMENSELY appreciated.
Edited by: Tracekill on Sep 13, 2009 11:01 AMStudy up on the javax.xml.parsers API here at Sun. Next, download Xerces from Apache (xml.apache.org). Finally, take a tutorial.
- Saish -
DOM XML Parser in Stateless Session Bean- Not able to generate Container
I am trying to do some XML Parsing using a DOM Parser in a Stateless Session Bean. I am importing org.apache.xerces.parsers.DOMParser and trying the following statement DOMParser parser = new DOMParser();
Even though I am able to compile and generate the initial jar file. When I try to generate the container using the Weblogic Deployer GUI tool, the process keeps on going(I mean that I see the small window saying Container Generating working) and it never stops.
Any suggestions are welcome.Many thanks ksaks for replying.
Actually day before yesterday we were able to do something like this. But then I kept this thread open only to see if experts have some good way of doing this.
What I mean is if this way is industry standards in terms of design and does it follow the most popular way how experts do it?
I am asking this as WebProjects have webcontent/web-inf directory wherein we put those xsds and property files, but we do not have anything like this in an EJB project. so was just wondering if this is the correct way of doing it or not.
I am still following this approach because I had to proceed further in my development. Confirmation would erase any other doubts on this.
Hope you find time to reply.
Kind Regards,
user2205
Edited by: user2205 on Nov 10, 2008 11:43 PM -
HELP ::: DOM XML Parser
Hi,
I am trying to parse this xml.
<Node>MS
<Condition>BooleaaaaanOperator
<Operation>AND</Operation>
<Condition>NumberList
<Comment>Only destinations are allowed to be sent.</Comment>
<Type>0</Type>
<Number>083538</Number>
</Condition>
<Condition22>BooooooooooooleanOperator
<Operation1>NOT</Operation1>
<Condition55>BooleeeeeeeeeeanOperator
<Operation2>AND</Operation2>
<Condition33>ExtensionNr
<Comment>When Extension Number 2 is not set to 1 it indicates the content type of the message.</Comment>
<Number>2</Number>
<Value>1</Value>
</Condition33>
<Condition44>ExtensionNr
<Numm>101010101010101</Numm>
<Value>0-1002</Value>
</Condition44>
</Condition55>
</Condition22>
</Condition>
<Node>Fee
I can get the Numm string using the parser by this line
elementSub5.getFirstChild().getNextSibling().getNodeName())
BUT:: I cannot get the value of that node to print out, or set it to a variable.
I really need the 101010101010101 but cannot get them. I have tried everything.If you could post more code I could possibly help you out. Just post some code of where the problem is and I will look at it. I believe there is a getNodeValue() method and there may be a getTextContent() method or something... actually I think I ran into this problem before... you can pull the value out of the toString() method by using a substring.
I used something like this and it worked fine...
String data = node.toString();
data = data.substring(data.indexOf(":")+1, data.length()-1);
In your case perhaps you can try something like this...
String elementData = elementSub5.getFirstChild().getNextSibling().toString();
elementData = elementData.substring(elementData.indexOf(":")+1, elementData.length()-1);
That substring method may not be 100% accurate... you best bet is to just put the node to a string and by debugging the program look at what the string value is. You can then adjust the substring to grab the correct data from the XML.
You would think there is a better way to do this... but I could not find it and this way worked for me... -
DOM XML Parsing...
Hi All,
I need a sample code to parse the following xml...
<EMPLOYEE>
<RECORD>
<EMPID>12</EMPID>
<EMPNAME>ROCK</EMPNAME>
</RECORD>
<RECORD>
<EMPID>13</EMPID>
<EMPNAME>PETER</EMPNAME>
</RECORD>
<RECORD>
<EMPID>14</EMPID>
<EMPNAME>JOHN</EMPNAME>
</RECORD>
</EMPLOYEE>
I need a generic parser code, to parse the records and populate into employee table.
Thanks in Advance....
Regards,
SimbhuOne way is using supplied XML function
SQL> create table my_employee ( empid number primary key, empname varchar2(50));
Table created.
SQL> insert into my_employee
2 select extractValue(column_value, '/RECORD/EMPID') EMPID, extractValue(col
umn_value, '/RECORD/EMPNAME') EMPNAME from TABLE(
3 XMLSEQUENCE(
4 EXTRACT(
5 XMLTYPE(
6 '<EMPLOYEE> <RECORD> <EMPID>12</EMPID> <EMPNAME>
ROCK</EMPNAME></RECORD><RECORD><EMPID>13</EMPID><EMPNAME>PETER</EMPNAME></RECORD
<RECORD><EMPID>14</EMPID><EMPNAME>JOHN</EMPNAME></RECORD></EMPLOYEE>'7 ),
8 '/EMPLOYEE/RECORD'
9 )
10 )
11 ) tb;
3 rows created.
SQL> select * from my_employee;
EMPID EMPNAME
12 ROCK
13 PETER
14 JOHN
Better way is if you have XSD, register it into Oracle. Oracle will create underlying tables.
Best Regards
Erturk -
Hello
I am getting java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element error. This code is in java which is present in java embedding.
The SOA is parsing the xml in java code using oracle.xml.parser.v2 . This wont be a problem if the SOA uses default w3c DOM parser. How do i force SOA to use w3c DOM parser.
Is there any thing i can do with class loading?
Kindly help.
Regards
SharatCan you paste your java code here ? I assume, you must have tried type-casting.
-
XML Parser for Java v2. Applying XSLT to DOM tree
I encountered pretty weird behavior of XML Parser for Java v2.
While applying XSLT to XML document created in memory using DOM
interface I couldn't access element attributes. For example,
given the XML document:
<root>
<Item ID="00001">Value of Item 00001</Item>
<Item ID="00002">Value of Item 00002</Item>
</root>
and XSLT:
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>XSLT Test</TITLE>
</HEAD>
<BODY>
<xsl:for-each select="/Error">
<H1>Error</H1><xsl:value-of select="."/>
</xsl:for-each>
<TABLE border="0" cellspacing="0" cellpadding="2">
<TBODY>
<xsl:for-each select="/root">
<TR>
<TH style="background-color:khaki">
<xsl:text>Attribute</xsl:text>
</TH>
<TH style="background-color:khaki">
<xsl:text>Value</xsl:text>
</TH>
</TR>
<xsl:for-each select="Item">
<TR>
<TD><xsl:value-of select="@ID"/></TD>
<TD><xsl:value-of select="."/></TD>
</TR>
</xsl:for-each>
</xsl:for-each>
</TBODY>
</TABLE>
</BODY>
</HTML>
</xsl:template>
If I build DOM tree by parsing XML file the resulting HTML
document after applying XSLT will display
Attribute Value
00001 Value of Item 00001
00002 Value of Item 00002
But if I build DOM tree using following code:
XMLDocument xDoc = new XMLDocument();
Element root = xDoc.createElement( "root" );
xDoc.appendChild( root );
Element elem = xDoc.createElement( "Item" );
elem.setAttribute( "ID", "00001" );
root.appendChild( elem ).
appendChild( xDoc.createTextNode( "Value of Item 00001" ) );
elem = xDoc.createElement( "Item" );
elem.setAttribute( "ID", "00002" );
root.appendChild( elem )
.appendChild( xDoc.createTextNode( "Value of Item 00002" ) );
the same XSLT will produce the following HTML output:
Attribute Value
Value of Item 00001
Value of Item 00002
So the value for the ID attribute is not displayed. At the same
time I can access this attribute using DOM interface. For
example, following code
NodeList nList = xDoc.getElementsByTagName( "Item" );
Element e;
for( int i = 0; i < nList.getLength(); i++ )
e = (Element)nList.item( i );
System.out.println( "ID: " + e.getAttribute( "ID" ) );
produces an output
ID: 00001
ID: 00002
Here is the code for applying XSLT to DOM tree:
DOMParser parser = new DOMParser();
parser.parse( new FileInputStream( "test.xsl" ) );
XMLDocument xsldoc = parser.getDocument();
XSLStylesheet xsl = new XSLStylesheet( xsldoc, createURL( "" ) );
XMLDocument out = new XMLDocument();
out.appendChild( new XSLProcessor().processXSL(xsl, xDoc) );
out.print( new FileOutputStream( "test.html" ) );
Andrei Filimonov
nullWe are not getting what you're getting on Solaris. See the
following:
Script started on Tue Jun 22 18:53:56 1999
Processing /view/test/vobs/oracore3/.ndeprodrc.csh
Processing /private/.nderc.csh
[test] > cat bruno.xml
<my_grandpa age="88">
<my_dad age="66">
<me age="44">
<my_son age="22">
</my_son>
</me>
</my_dad>
</my_grandpa>
[test] > cat bruno.xsl
<?xml version="1.0"?>
<!-- Identity transformation -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="me">
<xsl:value-of select="my_son/@age"/>
<xsl:value-of select="@age"/>
<xsl:value-of select="../@age"/>
<xsl:value-of select="../../@age"/>
</xsl:template>
</xsl:stylesheet>
[test] > java XSLSample bruno.xsl bruno.xml
<root>
22446688
</root>
[test] > exit
script done on Tue Jun 22 18:54:22 1999
What platform are you on and does your stylesheet and xml doc
match ours?
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
Bruno Bontempi (guest) wrote:
: I had a similar problem in accessing element attributes from
an
: XSLT sheet.
: It seems like the processor correctly accesses element
attributes
: in the context node, but does not retrieve values of
attributes
: outside the context node.
: For example, for an XML document like:
: <my_grandpa age="88">
: <my_dad age="66">
: <me age="44">
: <my_son age="22">
: </my_son>
: </me>
: </my_dad>
: </my_grandpa>
: and an XSL stylesheet like:
: <xsl:template match="me">
: <xsl:value-of select="my_son/@age"/>
: <xsl:value-of select="@age"/>
: <xsl:value-of select="../@age"/>
: <xsl:value-of select="../../@age"/>
: </xsl:template>
: I expect an output like:
: 22446688
: but all I get is
: 44
: I am also using Jim Clark's XT, which is returning the
expected
: result.
: Thanks in advance for your help,
: Bruno.
: Andrei Filimonov (guest) wrote:
: : I encountered pretty weird behavior of XML Parser for Java
v2.
: : While applying XSLT to XML document created in memory using
DOM
: : interface I couldn't access element attributes. For example,
: : given the XML document:
: : <root>
: : <Item ID="00001">Value of Item 00001</Item>
: : <Item ID="00002">Value of Item 00002</Item>
: : </root>
: : and XSLT:
: : <xsl:template match="/">
: : <HTML>
: : <HEAD>
: : <TITLE>XSLT Test</TITLE>
: : </HEAD>
: : <BODY>
: : <xsl:for-each select="/Error">
: : <H1>Error</H1><xsl:value-of select="."/>
: : </xsl:for-each>
: : <TABLE border="0" cellspacing="0" cellpadding="2">
: : <TBODY>
: : <xsl:for-each select="/root">
: : <TR>
: : <TH style="background-color:khaki">
: : <xsl:text>Attribute</xsl:text>
: : </TH>
: : <TH style="background-color:khaki">
: : <xsl:text>Value</xsl:text>
: : </TH>
: : </TR>
: : <xsl:for-each select="Item">
: : <TR>
: : <TD><xsl:value-of select="@ID"/></TD>
: : <TD><xsl:value-of select="."/></TD>
: : </TR>
: : </xsl:for-each>
: : </xsl:for-each>
: : </TBODY>
: : </TABLE>
: : </BODY>
: : </HTML>
: : </xsl:template>
: : If I build DOM tree by parsing XML file the resulting HTML
: : document after applying XSLT will display
: : Attribute Value
: : 00001 Value of Item 00001
: : 00002 Value of Item 00002
: : But if I build DOM tree using following code:
: : XMLDocument xDoc = new XMLDocument();
: : Element root = xDoc.createElement( "root" );
: : xDoc.appendChild( root );
: : Element elem = xDoc.createElement( "Item" );
: : elem.setAttribute( "ID", "00001" );
: : root.appendChild( elem ).
: : appendChild( xDoc.createTextNode( "Value of Item
00001" )
: : elem = xDoc.createElement( "Item" );
: : elem.setAttribute( "ID", "00002" );
: : root.appendChild( elem )
: : .appendChild( xDoc.createTextNode( "Value of Item
00002" )
: : the same XSLT will produce the following HTML output:
: : Attribute Value
: : Value of Item 00001
: : Value of Item 00002
: : So the value for the ID attribute is not displayed. At the
same
: : time I can access this attribute using DOM interface. For
: : example, following code
: : NodeList nList = xDoc.getElementsByTagName( "Item" );
: : Element e;
: : for( int i = 0; i < nList.getLength(); i++ )
: : e = (Element)nList.item( i );
: : System.out.println( "ID: " + e.getAttribute( "ID" ) );
: : produces an output
: : ID: 00001
: : ID: 00002
: : Here is the code for applying XSLT to DOM tree:
: : DOMParser parser = new DOMParser();
: : parser.parse( new FileInputStream( "test.xsl" ) );
: : XMLDocument xsldoc = parser.getDocument();
: : XSLStylesheet xsl = new XSLStylesheet( xsldoc, createURL
: : XMLDocument out = new XMLDocument();
: : out.appendChild( new XSLProcessor().processXSL(xsl, xDoc) );
: : out.print( new FileOutputStream( "test.html" ) );
: : Andrei Filimonov
null -
XML validation using XDK DOM/SAX Parser
Hello,
I am trying to validate xml against xsd using SAX/DOM parser, both the files are stored as CLOB column in the database. I have the requirement to report all the validation errors and based on some helpful advice/code from the earlier posts in this forum, I have used the following code to validate and report the errors.
The code works fine but for large files it never goes beyond a certain number of errors i.e. getNumMessages() (XMLParseException) never returns value greater than 100 and thus limits the output of the validation errors. Any pointers to suggest change in code or an alternative will be extremely helpful.
Datebase Version : Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED as package <package name>;
import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;
import oracle.sql.CLOB;
import oracle.xml.parser.schema.*;
import oracle.xml.parser.v2.*;
import org.w3c.dom.*;
public class XMLSchemaVal
public static String validate(CLOB xmlDoc, CLOB xsdDoc)
throws Exception
//Build Schema Object
XSDBuilder builder = new XSDBuilder();
Reader xsdInUnicodeFormat = xsdDoc.getCharacterStream();
XMLSchema schemadoc = (XMLSchema)builder.build(xsdInUnicodeFormat, null);
//Build XML Object
Reader xmlInUnicodeFormat = xmlDoc.getCharacterStream();
// Genereate the SAX
SAXParser saxparser_doc = new SAXParser();
// Set Schema Object for Validation
saxparser_doc.setXMLSchema(schemadoc);
saxparser_doc.setValidationMode(XMLParser.SCHEMA_VALIDATION);
saxparser_doc.setPreserveWhitespace (true);
String returnValue;
try {
saxparser_doc.parse (xmlInUnicodeFormat);
returnValue = "The input XML parsed without errors.\n";
catch (XMLParseException se) {
returnValue = "Parser Exception: ";
for (int i=0 ; i < se.getNumMessages(); i++)
returnValue += "<LN: " + se.getLineNumber(i) + ">: " + se.getMessage(i);
//returnValue = "Parser Exception: " + se.getNumMessages();
catch (Exception e) {
returnValue = "NonParserException: " + e.getMessage();
return returnValue;
Function to call the above utility from PL/SQL
CREATE OR REPLACE FUNCTION F_XMLSCHEMAVALIDATION (P_XML IN clob ,P_XSD IN clob) RETURN VARCHAR2 IS
LANGUAGE JAVA NAME XMLSchemaVal.validate(oracle.sql.CLOB,oracle.sql.CLOB) return java.lang.String';
Thanks.I have the same question. I have an external DTD. I wish to parse an xml file using XMLParser.xmlparse. If I first call XMLParser.xmlparseDTD and then call xmlparse with the XML_FLAG_VALIDATE will the xml automatically be validated against the previously parsed DTD? There is no DOCTYPE declaration in the xml file.
The demo code on OTN for Java is great but has no relation to the code you would use in C++ (no set functions in C++). -
I have the following problem:
I get my xml-documents as an XMLType from the database and want to compare these using the supplied Oracle class oracle.xml.differ.XMLDiff (i use the java version supplied with Oracle 9i r2).
XMLType.getDOM() returns the xml-document as a org.w3c.dom.Document,
what i need for oracle.xml.differ.XMLDiff is a oracle.xml.parser.v2.XMLDocument.
How can i cast/convert between these two formats?
thanks!
p.s. cross-posting with Re: Casting/Converting XMLType to XMLDocument? (but i think this forum is more relevant).Hi,
thanks for the suggestion: i have written the code shown below. It results in a casting error.
As far as i know, i don't use a oracle.xdb.dom.XDBDocument, i only use a oracle.xdb.XMLType as the input parameter for my conversion-method:
any new suggestions ???
p.s. the second method which is commented does work, but is a bit verbose.
private static oracle.xml.parser.v2.XMLDocument convert2XMLDocument(XMLType xml) {
// simple version (should work according to tech. doc. 9i r2/ 10g r1 database)
oracle.xml.parser.v2.XMLDocument doc = null;
try {
// n.b. probleem is dat XMLType.getDOM() een w3c.Document object teruggeeft ipv een oracle.XMLDocument.
System.out.println("convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.");
doc = (oracle.xml.parser.v2.XMLDocument) xml.getDOM(); // public org.w3c.dom.Document getDOM()
System.out.println("convert2XMLDocument(): done casting w3c.Document naar oracle.XMLDocument.");
catch (Exception e) {
e.printStackTrace(System.out);
return doc;
private static XMLDocument convert2XMLDocument(XMLType xml) {
// complex version: works ok !!!
XMLDocument doc = null;
try{
DOMParser parser = new DOMParser();
parser.setValidationMode(oracle.xml.parser.v2.XMLParser.NONVALIDATING);
parser.setPreserveWhitespace (true);
parser.parse(new StringReader(xml.getStringVal()));
doc = parser.getDocument();
catch ( XMLParseException e ) {
e.printStackTrace(System.out);
catch ( SQLException e ) {
e.printStackTrace(System.out);
catch ( Exception e ) {
e.printStackTrace(System.out);
return doc;
convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.
java.lang.ClassCastException: oracle.xdb.dom.XDBDocument
at pnb.bdb.xml.testJDBC.convert2XMLDocument(testJDBC.java:305)
at pnb.bdb.xml.testJDBC.main(testJDBC.java:187) -
How to ignore empty text element while using DOM to parse xml??
hi everyone,
i am using DOM to parse an xml file. But i dont know how to cinfig the DocumentBuilderFactory to ignore empty text elements.
For example, i have an xml file like this:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<child>Tom</child>
<child>Jerry</child>
</root>I used the following codes to parse:
String fname = "Tom-and-Jerry.xml";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
// Generate a DOM tree from the DOM builder.
org.w3c.dom.Document dom = builder.parse(new File(fname));
org.w3c.dom.NodeList list = dom.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
System.out.println("Child No."+i);
System.out.println("NodeName="+list.item(i).getNodeName());
System.out.println("NodeType="+getType(list.item(i).getNodeType()));
System.out.println("NodeValue="+list.item(i).getNodeValue());
System.out.println();
}The result is not exactly what i want ---- there are 5 children in list!! The 1st, 3rd and 5th are #text and their values are all empty. Only the 2nd and the 4th are the child that i expect.
It is really troublesome to get all these silly empty texts as sub elements. I tried to get rid of them, but i failed. I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.
Anyone can help me? thanks.
Heavy ZHENGI just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
http://www.w3.org/TR/REC-xml#sec-white-space -
Can I use a C/C++ xml parser in my java program?
Hi,
How can I use a C/C++ xml parser in my java program?
Elvis.You would still need to convert the XML data structure into a Java data structure to import it into Java.
Don't assume you need C++ to do anything. I woudl write it in Java first, then profile the application to see where the bottle necks are and then optimise them
Don't optimise code unless you have proof it needs to be optimised.
If you want to improve the speed of reading XML, try XMLbooster -
Accidentally clicked on "Allow for Safe Networks Only" and saved it. When launching Firefox, this error: XML Parsing Error: no element found
Location: jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/toolkit.jar!/content/global/netError.xhtml
Line Number 1, Column 1:
I have uninstalled and reinstalled, changed to a new profile, nothing works. I have looked at Options - Network - No Proxy
Please help as I love FirefoxStart Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
* Don't make any changes on the Safe mode start window.
See:
* [[Troubleshooting extensions and themes]] -
Creating a dynamic jtree using datas retrieved by dom in xml parsing
help me with code to create a dynamic jtree using data retrieved as nodes by xml parsing using dom
Ok, so you want to make a tree. To determine the data that appears in a tree, you have to make a custom tree model. The API for this is at :
http://java.sun.com/j2se/1.4.2/docs/api/
A tutorial for using trees is at :
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
I assume you are going to be using Nodes, since you are using XML. For this I might start with something like
class NodeTreeModel implements TreeModelI would then implement the 'getChildCount()' as the number of subnodes a node has, and the value of a tree node to the nodes value.
Hope that starts you off. -
Options for XML parsing in WAS 6.20 ABAP and higher
Hello Experts,
What options are available to me for working with XML documents in SAP R/3 4.7? I am working on SAP WAS 6.20 ABAP and was wondering which tools/techniques I can use for parsing XML files?
I am developing an ABAP program and primarily need to be able to parse XML documents. I need to be able to traverse up and down their data structures (trees/nodes/elements/etc.).
In SAP R/3 4.6 I used to use the iXML library but it seems that there are many advanced and powerful features included in SAP WAS 6.20 ABAP and up.
Could someone please give me a summary of and their opinions on some these "newer" options?
Thanks,
- Vik.Hi Vik,
There are two ways you can parse/interpret XML documents in ABAP -
1. iXML - Which you have already used in 46 release. It wasn't easy to use set of functions but still it was possible to parse documents using iXML library. In WAS 6.20 you can now use class CL_XML_DOCUMENT which is much more easier to use than iXML library. It is bilt on top of iXML using the same DOM model.
2. XSLT - Useing XSLT_TOOLS or XSLT transaction you can create XSLT programs to transform XML to ABAP data objects and then work with ABAP data objects. In this case you have the option of using some other tool like XMLSPY to write the XSLT and then copy that to SAP.
From your post it looks like you will probably have to traverse the tree in unpridictable way, probably DOM based parsing using CL_XML_DOCUMENT is more suitable for you.
Cheers,
Sanjeev -
Even Based XML Parsing in ABAP
Hi all ,
Currently i am using DOM Based Parsing to parse XML in my ABAP program. i am planning to change the code by using Event based parsing which is recommended for perfomance when we parse large xml document
Any one have the Example program for event based parsing the xml .pls help me in this.
Thanks in Advance
RamHello,
you can look at the coding example
data: event type ref to if_ixml_event,
event_sub type i
lp_dom type ref to if_ixml_document,
pstreamfac TYPE REF TO if_ixml_stream_factory,
pistream TYPE REF TO if_ixml_istream,
create the factory for streams
pstreamfac = g_ixml->create_stream_factory( ).
create the input stream:
pistream = pstreamfac->create_istream_cstring( string = xml ).
lp_dom = g_ixml->create_document( ).
create the iXML parser:
parser = g_ixml->create_parser(
stream_factory = pstreamfac
istream = pistream
document = lp_dom ).
let the parser know which events I am interested in
event_sub = if_ixml_event=>co_event_element_pre2 +
if_ixml_event=>co_event_element_post.
parser->set_event_subscription( events = event_sub ).
do.
event = parser->parse_event( ).
if event is initial.
exit. ' either end reached or error (check below)
endif.
data: str type string.
case event->get_type( ).
when if_ixml_event~co_event_element_pre2.
str = event->get_name( ). write: '<' str '>'.
when if_ixml_event~co_event_text_post.
str = event->get_value( ). write: str.
endcase.
enddo.
always check for errors:
if parser->num_errors( ) ne 0.
endif.
Regards,
Marc
Maybe you are looking for
-
My OS is 10.9.3.I've been working on a document in Pages 4.3. Now is says I can not open the document unless I upgrade to Pages 5.2. The Pages 5.2 page in the App store says "installed" nor can I find a "purchase" or "install" button. How do I get Pa
-
Transferring from another computer
I just got a Macbook and I wanted to transfer just my music from my IMAC. It ended up transferring everything now my memory is all taken up, I've tried erasing all of my pictures and movies. Is there anyway to start from scratch again?
-
Formula variable to add three char. date value together?
We've been struggling to use formula variable (Replacement Path), but never been sucessful! We have three row date type of char which are c1, c2, and c3. Now users would like to see a summation of the three date char. We believe we will have to use
-
Accessing data from Table control
Hi, I created a table control using report program and i am trying to enter data in the table control which i want to update in the DB table. How can i get the data entered in table control to the report program, so that i can update the DB table. Pl
-
The autoform in t:panelTabbedPane in tomahawk
I am using <t:panelTabbedPane> <t:panelTabbedPane> <t:panelTab> <h:form id="frm1"> <t:commandButton value="add"/> </h:frm> </t:panelTab> </t:panelTabbedPane> When I load the page I get a javascript error stating that the "elements is null". This is b