๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-parser
Best XML Parser Online
XML Parser Online helps to Edit, View, Analyse XML data along with formatting XML data. It's very simple and easy way to Parse XML Data and Share with others. To Access and Edit XML, Document Object Model of Extensible MarkUp Language defines ...
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ converters.html
Free Online Converter Tools For Developers - FreeFormatter.com
Let's you specify a prefix for XML attributes when converted to JSON properties
๐ŸŒ
Json2CSharp
json2csharp.com โ€บ code-converters โ€บ xml-to-csharp
Convert XML to C# Classes Online - Json2CSharp Toolkit
/* using System.Xml.Serialization; XmlSerializer serializer = new XmlSerializer(typeof(Realestates)); using (StringReader reader = new StringReader(xml)) { var test = (Realestates)serializer.Deserialize(reader); } */ [XmlRoot(ElementName="additionalCosts")] public class AdditionalCosts { [XmlElement(ElementName = "value")] public string Value { get; set; } [XmlElement(ElementName = "currency")] public string Currency { get; set; } [XmlElement(ElementName = "marketingType")] public string MarketingType { get; set; } [XmlElement(ElementName = "priceIntervalType")] public string PriceIntervalType
๐ŸŒ
Appspot
log4j-props2xml.appspot.com
Log4J Properties to XML Converter
This tool is a web front-end to the Log4J Properties Converter tool. Got a problem? Want the source?
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2012 โ€บ 03 โ€บ how-to-read-properties-file-in-java-xml.html
How to read Properties File in Java โ€“ XML and Text Example Tutorial
Now let's see another example of reading property files from xml format. as you know properties file in java can be represented in xml format and Java provides a convenient method called loadFromXML() to load properties from xml file.
Top answer
1 of 2
4

I was trying to do the same thing, and am really surprised to find no examples anywhere for JDBCAppender properties configuration.

What I did discover, since I'm using PAX logging under OSGI, I can refer to an XML config file by setting org.ops4j.logging.log4j2.config.file. Having got that to work, I've now gone back and figured out the properties approach, so I think this is what you are looking for:

appender.file.type = File
appender.file.name = fileAppender
appender.file.fileName = verdi.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d{YYYY-mm-dd HH:mm:ss.SSS} %-5p %c{1} - %m %n

appender.out.type = Console
appender.out.name = out
appender.out.layout.type = PatternLayout
appender.out.layout.pattern = %d{YYYY-mm-dd HH:mm:ss.SSS} %-5p %c{1} - %m %n

appender.db.type = Jdbc
appender.db.name = dbAppender
appender.db.tableName = LOGGING.APPLICATION_LOG
appender.db.cf.type = ConnectionFactory
appender.db.cf.class = log4j_tutorial.ConnectionFactory
appender.db.cf.method = getDatabaseConnection
appender.db.col1.type = Column
appender.db.col1.name = EVENT_DATE
appender.db.col1.isEventTimestamp = true
appender.db.col2.type = Column
appender.db.col2.name = LEVEL
appender.db.col2.pattern = %level
appender.db.col3.type = Column
appender.db.col3.name = LOGGER
appender.db.col3.pattern = %logger
appender.db.col4.type = Column
appender.db.col4.name = MESSAGE
appender.db.col4.pattern = %message
appender.db.col5.type = Column
appender.db.col5.name = THROWABLE
appender.db.col5.pattern = %ex{full}

rootLogger.level = INFO
rootLogger.appenderRef.file.ref = fileAppender
rootLogger.appenderRef.out.ref = out
rootLogger.appenderRef.db.ref = dbAppender

I haven't tried this exact config, since I'm using a DataSource rather than a ConnectionFactory, but I think that this should work in theory. I hope it helps.

EDIT: Add datasource definition lines as requested if datasource is required rather than connection factory:

appender.db.datasource.type = DataSource
appender.db.jndiName = osgi:service/dsName
2 of 2
3

I was trying to do the same and got this solution. 1. Create connectionFactory.java file

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.pool.impl.GenericObjectPool;

public class ConnectionFactory {

    private static interface Singleton {
        final ConnectionFactory INSTANCE = new ConnectionFactory();
    }
    private final DataSource dataSource;

    private ConnectionFactory() {
        Properties properties = new Properties();
        properties.setProperty("user", "aabsUser");
        properties.setProperty("password", "aj12fk18");

        GenericObjectPool pool = new GenericObjectPool();
        DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                "jdbc:mysql://localhost:3306/aabs", properties);
        new PoolableConnectionFactory(connectionFactory, pool, null,
                "SELECT 1", 3, false, false,
                Connection.TRANSACTION_READ_COMMITTED);

        this.dataSource = new PoolingDataSource(pool);
    }

    public static Connection getDatabaseConnection() throws SQLException {
        return Singleton.INSTANCE.dataSource.getConnection();
    }
}

2. make Entries in Log4j2.properties

name=PropertiesConfig
appenders=db
appender.db.type = Jdbc
appender.db.name = MySQLDatabase

# replace databaseName.tableName
appender.db.tableName =databaseName.tableName
appender.db.cf.type = ConnectionFactory

# change class path and method name
appender.db.cf.class = com.log4j2demo.ConnectionFactory
appender.db.cf.method = getDatabaseConnection
# define column type, column name and value
appender.db.col2.type = Column
appender.db.col2.name = DATE
appender.db.col2.isEventTimestamp = true

appender.db.col3.type = Column
appender.db.col3.name = LOG_LEVEL
appender.db.col3.pattern = %p

appender.db.col4.type = Column
appender.db.col4.name = FILE
appender.db.col4.pattern = %F

#Initialize logger
loggers=db
logger.db.name=com.log4j2demo.Demo
logger.db.level = All
logger.db.appenderRefs.db.ref = MySQLDatabase

#Initialize rootLogger
rootLogger.level =info
rootLogger.appenderRefs = db
rootLogger.appenderRef.db.ref = MySQLDatabase

3. Implement Logger

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Demo {

    private static Logger log = LogManager.getLogger();

    public static void main(String[] args) throws InterruptedException {
        log.trace("Entering application.");
        log.trace("Trace.");
        for (int i = 0; i < 10; i++) {
            log.info("Testing Lof For DB");
        }
        log.debug("Debug.");
        log.fatal("Fatal.");
        log.log(Level.WARN, "Warn");
        int a, b, c;
        a = 1;
        b = 0;
        try {
            c = a / b;
            log.info("vale of c" + c);
        } catch (Exception e) {
            log.error("error occur>>" + e);
        }
    }

}
Find elsewhere
๐ŸŒ
Phrase
support.phrase.com โ€บ hc โ€บ en-us โ€บ articles โ€บ 6111390496284--XML-Java-Properties-Strings
.XML - Java Properties (Strings) โ€“ Phrase
Java Properties XML is the XML equivalent of the Java Properties file. The keys of a Java Properties file exist as an attribute to the entry element in the XML while the values are inline text strings nested inside of the entry tags. Compared with the standard Java Properties files, the XML type provides higher flexibility in that you can add more attributes to the entry element.
๐ŸŒ
Json2CSharp
json2csharp.com โ€บ code-converters โ€บ xml-to-java
Convert XML to JAVA Object Online - Json2CSharp Toolkit
Convert any XML string to POJO objects online. Json2CSharp.com is a free toolkit that will help you generate JAVA classes on the fly.
๐ŸŒ
Blogger
source-files-translator.blogspot.com โ€บ 2016 โ€บ 05 โ€บ how-to-convert-xml-file-into-properties.html
How to convert XML file into Properties file?-Source Files Translator
Objective-C/Cocoa Property List (.plist),YAML (.yml),Java/Android Resources (.xml),Java Properties csv(.properties),JSON (.json),
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ xml-to-json-converter.html
Free Online XML to JSON Converter - FreeFormatter.com
This online tool allows you to convert an XML file into a JSON file. This process is not 100% accurate in that XML uses different item types that do not have an equivalent JSON representation. Attributes are treated as JSON properties and can be prefixed to differentiate them (@ is used by default)
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java xml โ€บ java convert properties file to xml file
Java Convert Properties File to XML File
March 9, 2023 - To convert an XML file to .properties file, follow the steps given in linked tutorial. 1. Create XML File from Properties File To convert the properties file into an XML file, the best way is to use java.util.Properties class.
๐ŸŒ
Count Words Free
countwordsfree.com โ€บ xmlviewer
Online XML Viewer
Check and review XML data with our online tool.
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 206962275-XML-property-Spring-configuration
XML property Spring configuration โ€“ IDEs Support (IntelliJ Platform) | JetBrains
The PropertyPlaceholderConfigurer is used to externalize property values from a BeanFactory definition, into another separate file in the standard Java Properties format. The JavaDoc for PropertyPlaceholderConfigurer makes similar statements. So I am not seeing any indication that you can pass in an XML file.
๐ŸŒ
engineerdatahelper
engineerdatahelper.wordpress.com โ€บ 2016 โ€บ 04 โ€บ 27 โ€บ xml-to-properties
How to convert XML file into Properties file? | engineerdatahelper
April 27, 2016 - See following XML file : <properties> <comment>Guide</comment> <entry key="seven-eight">load the original file or files</entry> <entry key="five-six">Settings and click Output directory</entry> <entry key="nine-ten">Choose a Properties Format</entry> <entry key="three-four">Start Conversion</entry> <entry key="one-two">Finished</entry> </properties> In this example, we show you how to use DataStorm to load above XML file into a properties object, it provided on Windows, Mac and Liunx platform.