Parse xml file and dynamically generate c++ code to build a panel(UI) - c++

I need to parse one xml file using c++ and dynamically populate a QT UI.
Any help in terms of tutorial, links, suggestions, source code example will be deeply appreciated. I have gone through most of the similar stack overflow links but its not helpful much.
Thanks in Advance.

Have a look at QXmlStreamReader and the Bookmarks example.
Basically what you want to do is open an XML file (using QFile), read it line by line and create the necessary UI-object (don't forget to close the file afterwards).
Let's assume your XML file looks something like this:
<ui>
<mainwindow width="800" height="600">
<label position="center">FOO</label>
...
</mainwindow>
</ui>
You'd use something like readNextStartElement() to read to <mainwindow ..>, read its attributes and call a method that creates a QMainWindow using the data you read. Then readNextStartElement() to <label ...>, call a method that creates the label and add it to the main window according to the atributes, and so on.

Related

QT C++ Project (Creating Login with XML)

I have question about my internship project. They want me to create a basic Login page(ID, Password). I create a XML file for Username and Password. The program should check the XML file for username and password*. If they are correct it will direct to a second window. I'm stuck on processing XML file for username and password. How can read those information in XML file.
As #JarMan said, I would recommend the QXmlStreamReader. You can fill it with a file (QIODevice), QString, QByteArray, etc...
Parsing a value could e.g. look like that
xml.attributes().value( attribute ).toString();
if attribute is a QString and xml is the QXmlStreamReader.
See the doc https://doc.qt.io/qt-5/qxmlstreamreader.html
There are several ways to do it. Marris mentioned one, but another one is to have this kind of code generated automatically. The way this works is that you first write an XML Schema that describes what your XML data looks like. An introduction to the XML Schema language can be found e. g. here.
Then you use an XML Schema compiler to translate the XML Schema to C++ classes. The schema compiler will also generate code to parse an XML file into objects, meaning you don't have to write any code to deal with XML by hand. It's a purely declarative approach: declare what the data looks like, and let the computer figure out the details.

How to add multiple attributes in same element in XML file in QT 4.8

I am looking add multiple attributes in my XML file using QT 4.8. It will be something like this:-
<Communication xmlns="http://tempuri.org/communication.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
For this use QXmlStreamWriter xw and create an element by this line:-
xw.writeStartElement(fileID);
Now I try to add my attributes:-
xw.writeAttribute("xmlns=","http://tempuri.org/communication.xsd");
xw.writeAttribute("xmlns:xs=","http://www.w3.org/2001/XMLSchema");
but unfortunately writeAttribute function can only work only just after creating element. Please read here about this. So, I am getting my output like this:-
<Communication xmlns:xs="http://tempuri.org/communication.xsd">
So, I wonder how can multiple attribute be added in same element. Please help. Thanks.

edit styles for normal.dotm template

My intention is to edit the Normal.dotm file from word.
All the links i read and the examples talk about open the file in word, which opens as a template, add the styles that i want and save to use it later to create new documents.
In these examples, when i open the file with word, i never see the characters inside the normal.dotm.
When i open the file with (for example) notepad or wordpad, it shows rare characters that i cant read.
It is possible to edit manually(or directly) or add the styles in the text inside the file? or the only way possible is to add the styles when i open the file with word as a template?.
I think once i found a link that said it was incorrect to directly add text to that file manually. But i am not sure of that.
Can you give me some advice?. Thank you.
This is the wrong forum for this type of question. SO is for questions about programming. In future please ask this sort of question on Super User.
To answer your question:
It is possible to edit Normal.dotm outside of Word but only if you are an expert in OOXML. If that is not the case open it inside Word using File | Open.
Documents in Word should be created from a template suited to the purpose, i.e. if you want to create letters first create a letter template with appropriate styles and content. You should not attempt to create all your documents based on the Normal template.

what is the actual meaning of parsing a html file?

I am not able to understand what actually parsing the html means ?
As i understand -
- it means that suppose we have any html file by parsing we can have the contents of the html file and we can edit them using parsing. Am i right ?? (parsing simply gives the idea about the contents and structure inside the file.)
I have one more question-
- I also want to know that suppose i have html file contents stored in a stream suppose (inside IStream *HTMLContents - No matter for now that how i got these contents). Is there any process exist that using these file contents may i create the preview on any window/Dialog Box/Preview pane with the same way exactly as i get the view of that html file in the browser.(for now you can imagine that i have downloded the HTML File contents from any web page(or from any where-No matter- But i have contents of html file in my stream i am sure about it) and i want to render that html file view in my own created window/Dialog Box/Preview pane(i mean it should view exactly as it appears in browser-Yes i know it won't be avle to display some pictures in html file but thats not a problem for me). How to do that ?? (I am using Visual c++ for my accomplishing my task)
Parsing basically means analyzing any data. When you parse HTML, it could be that you are figuring out where all the various elements are located and what do they do.
As for displaying HTML, it depends on what do you want to do:
If you want to open the file in your browser, use something like this.
As for displaying HTML directly in your form, I don't really know of any other way than parsing the HTML and creating your own web rendering engine. Good luck and have fun with that I guess.
Parse HTML means build object model such as DOM: https://en.wikipedia.org/wiki/Document_Object_Model in your program

c++ XML file parsing problem

Can any one tell me how to change an xml file using c++ and xercesc code?
My file is on my desktop using .
I know c++ file handling but don't know how to change attribute of xml file.
Can anybody tell me what I should do?
Any example, tutorial, book, etc., which can help me will be cordially accepted.
You can modify an attribute using the setAttribute function of class DomElement, as documentation says:
If an attribute with that name is already present in the element, its value is changed to be that of the value parameter.