Results 1 to 5 of 5

Thread: XML help

  1. #1
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Thumbs up XML help

    Hi Folks,
    I am trying this code :

    try {
    FileHandler fh = new FileHandler("C:\\Documents and Settings\\Desktop\\test\\logfile.xml",true);
    XMLFormatter xmlf = new XMLFormatter();
    fh.setFormatter(xmlf);
    Logger logger = Logger.getLogger("test.test1.test2");
    logger.addHandler(fh);
    logger.setLevel(Level.ALL);
    logger.warning("that is a test log message -- Level WARNING");
    logger.info("that is a second test log message -- Level WARNING");
    }
    catch (Exception e) {
    e.printStackTrace();
    }

    if i execute this for 2 times,it is coming up with 4 times:confused:...

    What i am doing means i am extracting some values from an invoice..the root must be same but for every invoice
    the xml should be appended with corresponding values when i execute the other invoice


    like:

    <root>
    <Invoice Details>
    <invoiceNo>1234</invoiceNo>
    <invoice Date>12-mar-2008 </invoice Date>
    <Amount>10000</Amount>
    </InvoiceDetails>
    <Invoice Details>
    <invoiceNo>5678</invoiceNo>
    <invoice Date>12-mar-2008 </invoice Date>
    <Amount>20000</Amount>
    </InvoiceDetails>
    </root>

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    It is unclear from your post what is coming up 2 or 4 times? Can you please clarify?

  3. #3
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    the output is coming like this:


    <?xml version.........>
    <root>

    <invoice Details>
    <Invoice No>123</Invoice No>
    <Invoice Amount>10000</Invoice Amount>
    </invoice Details>

    <?xml version.........>
    <invoice Details>
    <Invoice No>123</Invoice No>
    <Invoice Amount>10000</Invoice Amount>
    </invoice Details>

    <?xml version.........>
    <invoice Details>
    <Invoice No>456</Invoice No>
    <Invoice Amount>30000</Invoice Amount>
    </invoice Details>

    <?xml version.........>
    <invoice Details>
    <Invoice No>456</Invoice No>
    <Invoice Amount>20000</Invoice Amount>
    </invoice Details>

    </root>

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    I think the problem may lie in the code where you are writing the log messages. Can you post that?

    Also it seems to me that you are using the logging system for something that it is not meant for. It looks like all you are trying to do is parse the invoice and create an XML from it. I would recommend either filling a dom (using dom4j) or just writing out using a SAX writer and sax events. Even simple is to just write directly to the FileWriter. In the later case all you need to do is come up with your own escape routine which is pretty simple.

    My concern is that the logging mechanism is setup to do something different then what you want so you will most likely run into problems that you will have to work around and in the end would have been faster to just do one of the suggested techniques.

  5. #5
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •