Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to serialize XML files using qxorm. #103

Open
hs205118 opened this issue Jul 28, 2023 · 5 comments
Open

How to serialize XML files using qxorm. #103

hs205118 opened this issue Jul 28, 2023 · 5 comments

Comments

@hs205118
Copy link

hs205118 commented Jul 28, 2023

Hello!

I want to serialize XML files using qxorm.

Hi I find a document file: https://www.qxorm.com/qxorm_en/tutorial_3.html
shows that how I can compilation.
And after success to compilation, we still can not use "qx::serialization::xml", shows that xml namespace not define.
The environment I am using is VS2022

I see a sentence like this, but I don't know how to use it in vs2022:
Note : « QxOrm.pri » is a configuration file of QxOrm library. This file must be included in all dependents projects files (*.pro) adding the following line : include(my_path_to_QxOrm_library/QxOrm.pri)

@QxOrm
Copy link
Owner

QxOrm commented Jul 29, 2023

Hello,

Why do you prefer XML over JSON ?
The XML serialization is really strict, you can't for example change XML tags order, otherwise the deserialization fails.
This is why JSON serialization is recommended, this is much more flexible, and you don't need to add BOOST dependency.

If you really want to use BOOST XML serialization :

  • download BOOST
  • compile the boost seriailization library
  • in the QxOrm.pri file, enable this line :
# DEFINES += _QX_ENABLE_BOOST (line 55)
# DEFINES += _QX_ENABLE_BOOST_SERIALIZATION (line 72)
  • And you have to define some environment variable on Windows, as decribed here :
######################################
# Boost Library Configuration / Path #
######################################

# In this section, it's necessary to specify boost directories (lib + include) and boost serialization module name (debug + release) :
#  - QX_BOOST_INCLUDE_PATH (required) : your boost include path (by default, environment variable named BOOST_INCLUDE)
#  - QX_BOOST_LIB_PATH (optional) : your boost lib path (by default, environment variable named BOOST_LIB)
#  - QX_BOOST_LIB_SERIALIZATION_DEBUG (optional) : your boost serialization module name in debug mode (by default, environment variable named BOOST_LIB_SERIALIZATION_DEBUG)
#  - QX_BOOST_LIB_SERIALIZATION_RELEASE (optional) : your boost serialization module name in release mode (by default, environment variable named BOOST_LIB_SERIALIZATION_RELEASE)
#  - QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG (optional) : your boost wide serialization module name in debug mode (default is empty)
#  - QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE (optional) : your boost wide serialization module name in release mode (default is empty)
# Note : if _QX_ENABLE_BOOST_SERIALIZATION is not defined, then the only option used is QX_BOOST_INCLUDE_PATH (other options are ignored, QxOrm just needs to know how to find boost header files)

I would recommend to see the file : ./tools/msvc2019_build_all_debug_64b_full.bat
The 'full' means build with all QxOrm features, so with BOOST serialization.
This is done by CMAKE but this is the same thing for QMAKE.

@hs205118
Copy link
Author

Firstly, thank you for your reply.

Secondly, regarding 'Why do you prefer XML over JSON ?', it is because the program I am currently working on is to parse files provided by another system, so it requires XML reading and writing.

Then, it's sad that I still haven't successfully used qxorm: qx:: serialization:: xml on Visual Studio 2022
(1)I successfully compiled qxorm and referenced the file“ https://www.qxorm.com/qxorm_en/tutorial_3.html
(2)However, when I called qxorm: qx:: serialization:: xml, the provided XML was undefined.
(3)Therefore, in the "Preprocessor Definition" of vs2022, I added "_QX-ENABLE_BOOST; _QX-ENABLE_BOOST_SERIALIZATION
(4) And created a bat script to set the above environment variables:
setx QX_BOOST_INCLUDE_PATH "E:\Compare\QxOrm\boost_1_57\boost_1_57\include" /m
setx QX_BOOST_LIB_PATH "E:\Compare\QxOrm\boost_1_57\boost_1_57\lib_shared_64" /m
setx QX_BOOST_LIB_SERIALIZATION_DEBUG "boost_serialization-vc110-mt-gd-1_57" /m
setx QX_BOOST_LIB_SERIALIZATION_RELEASE "boost_serialization-vc110-mt-1_57" /m
setx QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG "boost_wserialization-vc110-mt-gd-1_57" /m
setx QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE "boost_wserialization-vc110-mt-1_57" /m

Then, I compiled my project and encountered a large number of compilation errors.
Can you help provide some more detailed operating steps? Thank you.

@QxOrm
Copy link
Owner

QxOrm commented Jul 31, 2023

to parse files provided by another system, so it requires XML reading and writing.

In this case, I'm pretty sure boost XML serialization is not for your project, as I said :

The XML serialization is really strict, you can't for example change XML tags order, otherwise the deserialization fails.

boost XML serialization is useful if it is used by the same program, but not to receive XML stream from external applications.

What you could do however, but it requires a bit of work on your side, is to create your own XML serialization/deserialization engine based on QxOrm introspection/reflection engine :
Documentation QxOrm introspection/reflection engine

@hs205118
Copy link
Author

hs205118 commented Aug 1, 2023

I don't need external programs to receive XML streams, and I don't need communication between my two applications. Instead, I use my current program to parse the XML file generated by the previous program (which will be copied in other ways). After parsing, it is regenerated into a separate XML file. (Finally copied away)

So, I just need to call qx:: serialization:: xml:: to_ File (tt, "D: export_drug.xml"); And qx:: serialization:: xml:: from_ File(tt2, "D: export_drag. xml");

However, I failed to use this.
I think I have successfully compiled the lib that supports xml, but the Header file does not declare xml related functions. As mentioned above, after defining the relevant macros, there were many errors in compilation.

So, my question is:
How can I use serialization of this XML in vs2022?

@QxOrm
Copy link
Owner

QxOrm commented Sep 12, 2023

Hello,
Sorry for the late response.
I don't know if this is ok for you now, but there is nothing more expect what I said previsouly :

    download BOOST
    compile the boost seriailization library
    in the QxOrm.pri file, enable this line :

# DEFINES += _QX_ENABLE_BOOST (line 55)
# DEFINES += _QX_ENABLE_BOOST_SERIALIZATION (line 72)

    And you have to define some environment variable on Windows, as decribed here :

######################################
# Boost Library Configuration / Path #
######################################

# In this section, it's necessary to specify boost directories (lib + include) and boost serialization module name (debug + release) :
#  - QX_BOOST_INCLUDE_PATH (required) : your boost include path (by default, environment variable named BOOST_INCLUDE)
#  - QX_BOOST_LIB_PATH (optional) : your boost lib path (by default, environment variable named BOOST_LIB)
#  - QX_BOOST_LIB_SERIALIZATION_DEBUG (optional) : your boost serialization module name in debug mode (by default, environment variable named BOOST_LIB_SERIALIZATION_DEBUG)
#  - QX_BOOST_LIB_SERIALIZATION_RELEASE (optional) : your boost serialization module name in release mode (by default, environment variable named BOOST_LIB_SERIALIZATION_RELEASE)
#  - QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG (optional) : your boost wide serialization module name in debug mode (default is empty)
#  - QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE (optional) : your boost wide serialization module name in release mode (default is empty)
# Note : if _QX_ENABLE_BOOST_SERIALIZATION is not defined, then the only option used is QX_BOOST_INCLUDE_PATH (other options are ignored, QxOrm just needs to know how to find boost header files)

I would recommend to see the file : ./tools/msvc2019_build_all_debug_64b_full.bat
The 'full' means build with all QxOrm features, so with BOOST serialization.
This is done by CMAKE but this is the same thing for QMAKE.

FYI, each release of QxOrm library is tested with boost XML serialization enabled.
And QxEntityEditor application is built with boost XML serialization enabled.
So if you still have issues, I think this is your environment which is not correct somewhere, but this is very difficult to help you on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants