Parsing With Digester

How can I parse a document like this and Display result like below.
<?xml version="1.0" encoding="UTF-8"?>
<countries>
<country>
     <name>Afganistan</name>
     <id>AFG</id>
</country>
<country>
     <name>Akrotiri</name>
     <id>AKR</id>
</country>
<country>
     <name>Albania</name>
     <id>ALB</id>
</country>
</countries>Result:
Country-AFG-Afganisthan
Country-AKR-Akrotiri
Country-ALB-Albania

If you mean apache commons digester, then that maps the XML to objects, so you need to create classes with fields that mimic the XML data, and methods in the classes to output the strings you want. I can't help you with the rules, as I haven't used digester, and the rest is trivial if verbose. Unless you really want to have the data as application specfic in-memory objects, I wouldn't use digester.
Pete

Similar Messages

  • XML parsing with digester

    Hi all,
    I'm trying to parse the following xml document:
    <?xml version="1.0" encoding="UTF-8"?>
    <map>
         <entry key='PAGE2.SNOME'>
              <bean key='nomeCliente'>field</bean>
         </entry>
         <entry key='PAGE3.TIPO_CONSTRUCAO'>
              <bean key='tipoConstrucao'>radio</bean>
         </entry>
    </map>with Digester. I'm trying to create a Map that holds Maps as Objects. My first approach was:
    Digester digester = new Digester();
    digester.addObjectCreate("map", HashMap.class);
    digester.addObjectCreate("map/entry", HashMap.class);
    digester.addCallMethod("map/entry", "put", 2);
    digester.addCallParam("map/entry", 0, "key");
    digester.addCallMethod("map/entry/bean", "put", 2);
    digester.addCallParam("map/entry/bean", 0, "key");
    digester.addCallParam("map/entry", 1);But it didn't return the results i expected. Is the order of the instructions wrong? What do i have to change to fix it?
    Hope someone can help me with this.
    Cheers,
    Carlos Ferreira

    Element rootelement = document.getDocumentElement();
    mainNodes = rootelement.getChildNodes();
    for(int i = 0; i<mainNodes.getLength(); i++) {
       Node eachParent = mainNodes.item(i);
       if(!eachParent.getNodeName().equals("#text")) {
          System.out.println(eachParent.getNodeName());
          for(Node child= eachParent.getFirstChild(); child != null; child=child.getNextSibling()) {
             if(!child.getNodeName().equals("#text")) {
                System.out.println(child.getNodeName()+" --- "+child.getFirstChild().getNodeValue());
    }This (your) code will only process the directchild nodes of your rootelement!
    try something like this instead:
    public void processDocument(Document document) {
       processElement(document.getDocumentElement();
    public void processElement(Node node) {
       if(!(node instanceof TextNode)) {
          System.out.println(eachParent.getNodeName());
          NodeList nodeChildren = node.getChildNodes();
          for(int i=0; i<nodeChildren.getLength(); i++) {
             proecessElement(nodeChildren.item(i));
    }

  • DBMS_SQL.PARSE with PL/SQL types

    Hi
    I need to use DBMS_SQL.PARSE with PL/SQL types defined in a package.
    I tried with a type record in a declare ..begin..end  script but I got an error ..(on second parameter):
    DBMS_SQL.PARSE(cursor_name, XXXXX, DBMS_SQL.NATIVE);
    It's possible?
    WIth SQL types defined at schema level it's works (es. Objects types) .
    If it's not possible, how can I resolve?
    Stefano

    Again, please post what XXXXX is. In order to use package declared types:
    SQL> create or replace
      2    package pkg1
      3      is
      4        type emp_rec
      5          is record (
      6                     empno number,
      7                     ename varchar2(10)
      8                    );
      9        type emp_rec_tbl
    10          is
    11            table of emp_rec
    12            index by pls_integer;
    13        g_emp_rec_tbl pkg1.emp_rec_tbl;
    14  end;
    15  /
    Package created.
    SQL> declare
      2      v_cur integer;
      3      v_sql varchar2(1000);
      4  begin
      5      v_cur := dbms_sql.open_cursor(2);
      6      v_sql := 'begin
      7                    select  empno,
      8                            ename
      9                      bulk  collect
    10                       into  pkg1.g_emp_rec_tbl
    11                       from  emp
    12                       where job = ''CLERK'';
    13                end;';
    14      dbms_sql.parse(
    15                     v_cur,
    16                     v_sql,
    17                      dbms_sql.native
    18                     );
    19  end;
    20  /
    PL/SQL procedure successfully completed.
    SQL>
    SY.

  • Ignoring white lines in a file parsed with Scanner

    I've a little problem...
    How to ignore white lines in a file (for configuration informations) parsed with Scanner???
    My parser can ignore #(comments) and other thing, but not white lines...
    oooo
    fucking little problem!!!
    Thank for solutions...
    euronymous

    Wrong assumption. Scanner doesn't return lines, it returns tokens separated by delimiters which are whitespace by default, so by default it will already ignore blank lines.
    If you are using custom delimiters, make sure to include space, tab, and newline (\r \n and \f) as delimiters.

  • JDBCRealm with digested passwords.

    Hi,
    I've sucessfully set up a JDBCRealm to accept users and there log in details but the passwords are currently cleartext. I need to encrypt them with MD5.
    I've followed the instructions here:
    http://tomcat.apache.org/tomcat-3.3-doc/JDBCRealm-howto.html
    so I've added digest="MD5" to the Realm element in my server.xml file. The way i am trying to enter the user name and encrypted password details into the DB is as follows.
    stmt.executeUpdate(
                        "insert into users values('" + this.getUserName() +
                        "\', md5('" + this.getUserPassword() + "'));" );
    But I see in the instructions something about a static encryption method:
    final public static String digest(String password,String algorithm). in org.apache.tomcat.modules.aaa.RealmBase
    It says "the jar where RealmBase class can be found is %TOMCAT_HOME%/lib/container/tomcat_modules.jar" I do not have this jar in my tomcat installation. I am using tomcat 5.0.28. Can anyone give me any tips or links to help me get this working.
    Cheers,
    Joe.

    Hi Ive made some progress on this. It seems the MD5 encryption mysql uses differs slightly from the MD5 encryption tomcat uses. So I am trying to use MD5 encryption in tomcat to encrypt the password before inserting it into the DB. Heres the code I'm trying to use Note for now i have hardcoded the username to be root and the password to be password:
         public String getDigestedPassword()
              try {
                   // Obtain a new message digest with "digest" encryption
                   MessageDigest md = (MessageDigest) MessageDigest.getInstance("MD5").clone();
                   // encode the credentials
                   md.update("password".getBytes());
                   // Digest the credentials and return as hexadecimal
                   return (HexUtils.convert(md.digest()));
              } catch(Exception e) {
                   sm_log.error( "Error creating user", e );
         }Then in another method I have this:
                   ResultSet result = stmt.executeQuery(
                             "select * from users where user_name='root' and user_pass ='" +
                             this.getDigestedPassword() + "'" );
                   if(!result.first()){
                        result.moveToInsertRow();
                        result.updateString( 2, "root" );
                        result.updateString( 3, this.getDigestedPassword() );
                        result.insertRow();
                   }However I am having trouble finding the class HexUtils. I am getting this error:
    java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/HexUtils
    Am i missing something from my class path Is there a jar file I need. Any help appreciated.
    Cheers,
    Joe.

  • How to configure a Proxy in OSB with Digest Authentication?

    Hello, Guys.
    I need a help with this subject.
    I have a demand to configure a Proxy in OSB 11.1.1.6 with Digest Authentication. I'm using a Embedded Ldap with Identity Asserter.
    I'have configured a DefaultAuthenticator and the DefaultIdentityAsserter to support Digest Password and create a new LdapIdentityAsserter pointing to my embedded Ldap.
    When I'll create a new Proxy, in the security options, i can see the digest options to authenticate my username and password. I selected the one of all the options, but in the time of the Proxy test the authentication didn't work.
    Could anyone help me?
    Thanks you.

    Unfortunately, a reference trigger can't be used for continuous acquisition after the trigger. The maximum post-trigger count is either 2^24 or 2^32 depending on your hardware. Depending on your sampling rate and how many samples you expect to acquire before issuing a software stop, using the max post-trigger count may be sufficient for you. There are a couple of other options I can think of that you might want to try:
    1.) If possible, play with the trigger condition such that it occurs at the start of your pre-trigger data and use it as a start trigger instead. I suspect this may not be possible.
    2.) Set up a continuous acquisition and implement detection of the trigger condition through software. This is more software work and is more CPU intensive than the hardware solution, but it can definitely be made to work.
    3.) With some creative use of the counters, you may be able to latch the sample clock number that trigger occurred on. This would allow you to setup a continuous acquisition and use the hardware to tell you where the trigger occurred instead of figuring it out in software. What I'm thinking is you would set up a buffered event counting task with the ai/SampleClock as the timebase source of the counter and the trigger signal as the sample clock of the counter. By reading the first count value, you should know which AI sample the trigger occurred. From there, you can seek to the right position in the buffer and begin reading data indefinitely.
    Good luck!

  • Does NW7.4 ABAP stack still not support usernametoken with digest password?

    Hello, experts,
    I got the message from here Username Token with digest password on AS ABAP that NW7.0 ABAP STACK can't support usernametoken with digest password.
    Does NW7.4 ABAP stack still not support usernametoken with digest password?
    or can I custom the method VERIFY_USERNAME_TOKEN in CL_WS_SECURITY_PROFILE to support usernametoken with digest password?
    or does sap have any plan to support this security requirement?
    Many thanks.
    fangzj

    I asked my experts about your question. On the client side we support this. We cannot support digest passwords on the server side. We save passwords in hashed format on the server side. To support digest passwords, the client would either need to send the password in clear text so that the digest can be calculated or the server would have to store the password in clear text, so that the digest password can be calculated. From a security standpoint these are questionable ideas. Either an eavesdropper is picking up the passwords from the traffic or the attacker who breaks the server suddenly has all the passwords in clear text.
    You can modify the method VERIFY_USERNAME_TOKEN, but if an upgrade comes along that changes this package, you'll be prompted for a correction import. Then you will either have to skip the upgrade or lose your customization.
    -Michael

  • XML parser with document support

    Hi all,
    For a whole week now, I m still looking for a nice (but lite) XML parser for J2ME applications. Of course I found kXML 2 parser but I'm confused.
    kXML 2 implements the XmlPull API (xmlpull.org) so you can parse easly an XML file with functions as next(), ...
    BUT, I would like to deal with a Document Object Model (DOM) (like JDom for J2SE), with this I will be able to do some nice stuff like doc.getRoot().getElement....
    In kXML2 Javadoc I found something like this but apparently it doesnt work well (or I dont know how to use it).
    Do someone know this API ? http://kxml.sourceforge.net/kxml2/javadoc/
    I can't find any example on Internet, everybody seems to use it without DOM....
    Until someone give me an answer I will continue to use kXML2 without document object model :(
    thanks guys,

    just a search..in http://sourceforge.net/
    http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=dom+j2me

  • XML Parsing with Tags increasing in no's

    I have an XML that I am recieving it from other system like below :
    <ResultSet>
      <ERROR_CODE_ID>0</ERROR_CODE_ID>
      <ERROR_DESCRIPTION>Success</ERROR_DESCRIPTION>
    <Rows>
    <Row1>
      <RATE_EFFECTIVE_DT>2013-08-24
    00:00:00.0</RATE_EFFECTIVE_DT>
    <INDEX_NAME>LN-EBOR-7D-AED              
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>7D</TERM>
      <TERM_NO>7</TERM_NO>
      <TERM_PERIOD>D</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.15430000</RATE>
    </Row1>
    <Row2>
      <RATE_EFFECTIVE_DT>2013-08-26
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR- 1M-AED  
               </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>1M</TERM>
      <TERM_NO>1</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.52430000</RATE>
    </Row2>
    <Row3>
      <RATE_EFFECTIVE_DT>2013-08-25
    00:00:00.0</RATE_EFFECTIVE_DT>
    <INDEX_NAME>LN-EBOR-2M-AED              
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>2M</TERM>
      <TERM_NO>2</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.66710000</RATE>
    </Row3>
    <Row4>
      <RATE_EFFECTIVE_DT>2013-08-24
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR-
    3M-AED             
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>3M</TERM>
      <TERM_NO>3</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.86140000</RATE>
    </Row4>
    <Row5>
      <RATE_EFFECTIVE_DT>2011-05-23
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR-
    4M-AED             
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>4M</TERM>
      <TERM_NO>4</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.0</RATE>
    </Row5>
    </Rows>
    </ResultSet>
    The data is comming in multiple row tag with Row1,Row2,Row3...so on.
    I am not able to parse the XML with Row1,Row2..etc. I need some help.

    Do you want to do this using Oracle database (which version?), or some other tools ?

  • Can't use DTD without a "file:" while parsing with SAX2 parser

    Hello,
    I'm using JDK 1.4 with JAXP parser.
    I'm trying to parse an xml document that use a dtd.
    The DTD is in same dir as the xml file.
    If i use a "file:./" before mydtd.dtd like this :
    <!DOCTYPE doc SYSTEM "file:./mydtd.dtd">
    It is working fine, but if i declare it as
    <!DOCTYPE doc SYSTEM "mydtd.dtd">
    I've got a parsing SAX exception saying
    Relative URI "mydtd.dtd" can't be resolved without an URI of document. (translated)
    How to fix that ?

    I think your problem would be solved by using InputSource class. Use the setSystemId method. The relative URI will be resolved relative to the path you provide in this method.

  • Changing xmlschema while parsing with sax

    Hello world,
    I`m using the sax-parser (xerces) and i want to combine different schema-files to parse an xml-String;
    <root>
         <intervall>1,5</intervall>
         <nix>jetzt echt nix!</nix>
         <testtag>
              <text>huhu joe</text>
         </testtag>
         <theLast>das letzte element</theLast>
    </root>e.g. i want to parse the tag testtag with another schema ??
    does anyone have an idea or a sample coding ??
    thank you very much

    thank you for the reply, but i want to change the Schema file while parsing the xmlString with Sax, without manipulation the xmlString;
    the xml-String i get is fixed;
    wish you all a great sunday

  • Parsing with DOM results in file Size of the resultant Document(Urgent ....

    hai
    1.Iam parsing xml file to Dom document using DOM
    2.I have inserted element into the document.
    3.and rebuild the file with that document with TransformerFactory
    4.It results in reduce of file size.
    please help me with some guidance.............
    thanks in advance

    Some XML outputters do not write out return characters or tabs for new nodes. If your input contained these things, that could explain why the file shrank. I would check the data and see if it is all there. Other than that, don't worry about it.

  • How to use a parser with crimson XmlDocumentBuilder

    Hi,
    I'd be very grateful for any help on the following...
    I used to use the following code to parse an Xml document, using a SimpleElementFactory to create my own class Element nodes...
    XmlDocumentBuilder builder = new XmlDocumentBuilder();
    parser = new com.sun.xml.tree.ValidatingParser();
    parser.setDocumentHandler( builder );
    parser.parse( in );
    Docuent doc = buider.getDocument();
    This worked fine using the project X code. However after migrating to the crimson code I can't find a way to link my XmlDocumentBuilder with the parser.
    com.apache.crimson.parser.ValidatingParser seems to have no methods to link it to a com.apache.crimson.tree.XmlDocumentBuilder. If I follow a similar pattern to before the getDocument call returns null as the parser is not linked to the builder.
    Please could someone point out my obvious mistake!
    Many thanks

    Hello,
    I am using Crimson parser to parse an XML Document containing Czech characters. When I write the stuff read from the file, the output seems to be a corrupted one. It will be highly appreciable if someone can come up with any idea on where things might have gone wrong?
    The foll is the piece of code that reads and writes the XML.
    Writer xout = null;
    String inputXML     =     "content-chzech.xml";
    javax.xml.parsers.DocumentBuilderFactory xDbf     =     javax.xml.parsers.DocumentBuilderFactory.newInstance();
    javax.xml.parsers.DocumentBuilder     xDb     =     xDbf.newDocumentBuilder();
    Document xD                          =     xDb.newDocument();
    File xmlFile                          =      new File(inputXML);
    xD                              =      xDb.parse(xmlFile);
    XmlDocument xdoc                     = (XmlDocument) xD;
    xdoc.normalize();
    Writer writer = new BufferedWriter( new FileWriter( "parsedOutput.xml") );
    xdoc.write( writer);
    writer.close();

  • Problem with SAX parser with String format

    hi, all I have the next problem:
    I try to parse xml file with success, I write next code:
    ====================
    my_class saxUms = new my_class();
    File file = new File( "c:\\my_try_Response.xml" );
    InputSource src1 = new InputSource( new FileInputStream( file ) );
    XMLReader rdr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );          rdr.setContentHandler( saxUms );
    rdr.parse(src1);
    ===================
    but when I try to parse the same in string variable, I write:
    ===================
    my_class saxUms = new my_class();
    StringReader strr = new StringReader(my_str);
    InputSource intt = new InputSource(strr);
    XMLReader prs= XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
    prs.setContentHandler(saxUms);
    prs.parse(intt);
    ===================
    and error occurs:
              "Exception: java.lang.ClassCastException: java.lang.StringBuffer"
    how to fix the problem?
    Thank you for collaboration!

    where does the exception stack trace say the error is occurring?

  • Problem Using Sax parser with Eclipse 3.0 and command line

    Hi,
    I am parsing a xml file with sax. When I am running my programm in the command line everthing is ok and I get the right results from parsing.
    But if I am running the programm in Eclipse 3.0 (the same java code) I get an other result (the wrong results).
    Does anybody know what this can be the reason for. Is Eclipse using an other xml parser and if where I can change the parser?
    It would be very kind if somebody can give me a reason for this strange behaviour.
    Thanks in advance

    I have solved my problem.
    In the command line I used jre 1.4 and in Eclipse I used jre 1.5.
    I think jre 1.5 uses an other xml parser so I got an other result.
    If i use in Eclipse jre1.4 I get the same result as in the command line.

Maybe you are looking for

  • Font Book-marker in Photoshop, Illustrator and Indesign

    I guess we need a book-marker for fonts built-in all adobe softwares, some thing similar to the book markers in chrome or mozilla. Coz every artist working comfortably on adobe tools would not wish to go through all the tons n tons of fonts installed

  • To collect small slices into a secondary, callout pie chart in SSRS 2005

    Hi Guys,  There exists a property in pie chart in SSRS-2008 which can consolidate the small slices on pie chart. But I am unable to find the same property in SSRS-2005.  Is this property only available in SSRS-2008 ? If yes how can we achieve the sam

  • Frozen "Do Not Disconnect" Screen

    Hey guys I need some URGENT help: I recently "ejected" my ipod from my pc but what happened is that it took ages for "My Ipod" to disappear from my iTunes and it ended up having an error on my PC saying that the drive wasn't ejected successfully and

  • About HLD and LLD

    Hi experts,                  Can anybody help me in understanding what HLD and LLD are all about and what is the part of an abaper with respect to a HR ABAP project. Regards, Shanthi.

  • How to create the fact table

    pleae let me know how to create the fatc table by using pl/sql packages Edited by: 792988 on Sep 6, 2010 3:34 AM