Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. xml
    Log in to post

    • UNSOLVED Cannot read XSD attribute with QXMLStreamReader
      General and Desktop • xml qxmlstreamreade parsing xsd • • jepessen  

      4
      0
      Votes
      4
      Posts
      128
      Views

      I'm sorry but you must be moving the cursor in some way. Try putting Q_ASSERT(m_node.isStartElement()); just before auto x = m_node.attributes().size(); This example parses the XSD you provided correctly (I also let QXmlStreamReader handle namespaces instead of having to write custom code for it): int main() { const QString xmlText(R"***(<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name = "elementName"> <xs:simpleType> <xs:restriction base = "xs:string"> </xs:restriction> </xs:simpleType> </xs:element> </xs:schema>)***" ); QXmlStreamReader reader(xmlText); while (!reader.atEnd()) { switch(reader.readNext()){ case QXmlStreamReader::StartDocument: qDebug("Start of document"); break; case QXmlStreamReader::EndDocument: qDebug("End of document"); break; case QXmlStreamReader::StartElement:{ qDebug() << "Started Element: " << reader.name(); const auto attr = reader.attributes(); qDebug() << "Number of Attributes: " << attr.size() << " Attributes:"; for(auto&& att : attr) qDebug() << att.name() << " = " << att.value(); } break; case QXmlStreamReader::EndElement: qDebug() << "Finished Element: " << reader.name(); break; default: break; } } return 0; }
    • UNSOLVED Convert Json data into xml format
      General and Desktop • qt 5.4 c++11 xml json parser christian ehrli • • Durgesh  

      3
      0
      Votes
      3
      Posts
      61
      Views

      You need to be more specific. xml doesn't have arrays, how should arrays be treated?
    • SOLVED How to read whole child into a parent tag in xml?
      General and Desktop • xml qxmlstreamreade qxml • • Ripley  

      4
      0
      Votes
      4
      Posts
      160
      Views

      @mrjj Hey bro thanks a lot that article was help me a lot to solve it.
    • SOLVED Proper successor for QXmlSchemaValidator?
      General and Desktop • c++ xml qxmlstreamwrite qxmlschema xml pattern • • Robin Glattauer  

      6
      1
      Votes
      6
      Posts
      440
      Views

      A colleague asked for me on the mailing list and that was the answer: regarding the 'deprecated' state of XmlPatterns: There wont be an further development for this module, but I also doubt that it will be removed before Qt 6. So as long as you're using Qt 5 you're safe to use XmlPatterns. Qt 6 might be still 2 years away, and as you're using it professionally, I assume that you'll probably wait at least till the release of Qt 6.1 (or even longer) anyway before upgrading your project to it. Until then there might be another Qt (conforming) solution to the problem. So in my opinion you've got 2 options (depending on the scope and lifecycle of your project): a) use the Xml Schema related classes from the XmlPatterns module and worry about it going away (much) later, and maybe even have a Qt (conforming) solution by then, or b) use an external library like CodeSynthesis XSD or something similar and worry about their API changes and usage and naming patterns that differ from Qt's patterns etc. IMHO using the Qt modules while they are still available is usually the better option. [[by Yves Maurischat]] I hope that helps other developers with similar questions. I mark this as solved in the sense that there is some sort of answer here, although maybe it's not completely satisfying.
    • UNSOLVED General Purpose Data Serializer
      Showcase • xml serialization gpds • • Joel Bodenmann  

      7
      6
      Votes
      7
      Posts
      645
      Views

      We've added support for the first Qt types: QString and qreal. You can now do this: class Color : public Gpds::Serialize { public: QString name; int red; int green; int blue; virtual Gpds::Container toContainer() const override { Gpds::Container c; c.setComment("a color object"); c.addAttribute("format", "rgb"); c.addAttribute("name", name); c.addValue("red", red).addAttribute("depth", "32"); c.addValue("green", green).addAttribute("depth", "32"); c.addValue("blue", blue).addAttribute("depth", "32"); return c; } virtual void fromContainer(const Gpds::Container& c) override { // Retrieve format const QString& formatString = c.getAttribute("format").value_or("n/a"); assert( formatString == "rgb" ); name = c.getAttribute("name").value_or("n/a"); red = c.getValue<int>("red"); green = c.getValue<int>("green"); blue = c.getValue<int>("blue"); } }; Which will result in the following XML: <color format="rgb" name="Black"> <blue depth="32">0</blue> <green depth="32">0</green> <red depth="32">0</red> </color> There's also a Qt specific demo/example in the repo. Isn't the world wonderful? There's still a lot of stuff left to do tho.
    • UNSOLVED Draw a line with opengl using xml file
      General and Desktop • opengl gui xml qtopengl • • HW-Developer  

      2
      0
      Votes
      2
      Posts
      357
      Views

      @HW-Developer Start here http://doc.qt.io/qt-5/qtxml-index.html
    • UNSOLVED Write data to specific place in a XML file
      General and Desktop • xml save • • TMJJ  

      2
      0
      Votes
      2
      Posts
      452
      Views

      Hi, QDomDocument comes to mind for that kind of thing. There's no easy way to modify a file "in-place".
    • UNSOLVED Read and write QBrush (QPen, QFont) as XML
      General and Desktop • xml serialization qfont qbrush qpen • • TheTrueGoofy  

      6
      0
      Votes
      6
      Posts
      1252
      Views

      @TheTrueGoofy said in Read and write QBrush (QPen, QFont) as XML: Certainly this is also quite simple to implement, but I was hoping that there is a more elegant solution. I think the only other way is to create feature request for QtGui, or implement a Qt patch yourself - to add a QBrush::toString() method (or QTextStream overload), with a corresponding QBrush::fromString().
    • SOLVED Uploading an xml file to Qt app
      General and Desktop • file xml read upload • • Lasith  

      7
      0
      Votes
      7
      Posts
      1490
      Views

      @koahnig Thanx mate
    • SOLVED How to parse xml with inline (embedded tags)?
      General and Desktop • xml xml parsing qxmlstreamreade • • billconan  

      12
      0
      Votes
      12
      Posts
      3695
      Views

      Again, it wasn't a suggestion, I was just asking whether you would simply do tag for tag replacement. Out of curiosity, since you are using doxygen, why not make it generate the html directly ?
    • UNSOLVED Best Way to Read XML Tags w/o Specifying Tag's Name
      General and Desktop • xml xml parsing xmllistmodel xmllist • • masshakar  

      3
      0
      Votes
      3
      Posts
      829
      Views

      Hi, Creating a very "abstract" xml parser is not easy and it's quite error-prone. You have to know some (or at least one) parent or common tag names in order to have a starting point for any deeper "abstract" parsing. Basically, you have to move the parser step by step checking everything in the way. For example, you could use a simple function as an entry point for the following function when you meet a specific tag: void XmlReader::readFragment() { Q_ASSERT(m_reader->isStartElement()); //Make sure the xmlreader is at an opening tag const QString p = m_reader->qualifiedName().toString(); // From now on, you will work with this opening tag //Do what you want, for example handle attributes and their values for (auto i = 0; i < m_reader->attributes().count(); ++i) { ... } m_reader->readNext(); //Move on ... //Do everything manually like this if (m_reader->isCharacters) { ... } else if (m_reader->isEndElement()) { ... } //or like this //Eventually, you have to check for the closing current tag, exit the function, //and return the control to the "entry point" function while (!m_reader->isEndElement() && !m_reader->qualifiedName().toString() == p) { ... //Do your work m_reader->readNext(); } } However, with this approach, things can get extremely complicated if there are nested tags, for example: <p> <note> <p>...</p> </note> </p> Maybe it would be easier to subclass QXmlStreamReader but it would help to provide some sample xml data and more info on what exactly you want to do.
    • UNSOLVED Insert data after the corresponding node in XML
      General and Desktop • xml • • Pradeep Kumar  

      2
      0
      Votes
      2
      Posts
      487
      Views

      @Pradeep-Kumar Do you have your code please? Sounds like you're adding nodes at the root level. You need to insert a sibling after the first/second node.
    • UNSOLVED XML parsing
      General and Desktop • xml • • akshay123  

      8
      0
      Votes
      8
      Posts
      1647
      Views

      Thanks @yuvaram @jsulm @yuvaram . he XML which i have posted here is not in proper format . Since the XML is very big i wanted to post a small snippet of it . Thanks for your help .
    • Serialization, XML parse
      Showcase • c++ xml qxmlstreamreade serialize qxmlstreamwrite • • AstrA50  

      1
      2
      Votes
      1
      Posts
      807
      Views

      No one has replied

    • UNSOLVED Performance Issue - Reading XML Values with 50-70 entry.
      General and Desktop • c++ qt performance xml • • Mathan M  

      2
      0
      Votes
      2
      Posts
      716
      Views

      @Mathan-M Instead of QDom* you can use the QXmlStreamReader as the document says it is quite faster and memory efficient. Once you get to the parent node you can just use name and readElementText iteratively.
    • UNSOLVED Maintaining the list of downloads
      General and Desktop • c++ qt 5.7 xml • • Mathan M  

      6
      0
      Votes
      6
      Posts
      1208
      Views

      Hi @SGaist , Yes, I am maintaining the version in the xml file to compare the latest version maps are available. Thanks for the reply.
    • SOLVED Problem with Read and Write XML File
      General and Desktop • qt 5.5 xml xml parsing • • Punit  

      10
      0
      Votes
      10
      Posts
      2707
      Views

      @the_ said: I for myself do not like this format... No-one does ^_^
    • UNSOLVED xml write with only space or empty issue
      General and Desktop • xml xml parsing qxml qdom qt4.8.4 • • Narthan  

      7
      0
      Votes
      7
      Posts
      2808
      Views

      @Paul-Colby i am opening xml file as you mentioned first time when i pressed save button it will show <?xml version='1.0'?> <xml> <tag1> </tag1> // two spaces from line edit </xml> second time when i presses save button it will show <?xml version='1.0'?> <xml> <tag1/> // some data in lineedit </xml> third time when i presses save button it will show <?xml version='1.0'?> <xml> <tag1/> // some data in lineedit </xml> i am using Qt 4.8.7, i am opening xml file , see the result
    • UNSOLVED QObject serialization/deserialization library
      Showcase • qobject xml serialization properties tool • • Wilk  

      2
      0
      Votes
      2
      Posts
      1732
      Views

      @Wilk it's cool! What about JSON serialization? I will try to use your library in my project http://forum.qt.io/topic/64999/qt-micro-rest-client-framework-beta
    • SOLVED How can I get the info I need better than I do it right now?
      General and Desktop • combobox xml • • roseicollis  

      5
      0
      Votes
      5
      Posts
      1411
      Views

      @mrjj I don't know but never thought about it so that's why I did that "odd/botched job" and when you mentioned it was like a "Oh man! why didn't I thought in that before? Its so simple...." hahaha I'll keep it in mind henceforth.
    • UNSOLVED How to get the inner xml from a node using QXmlStreamReader?
      General and Desktop • xml qxmlstreamreade parsing inner xml • • ams_bob  

      1
      0
      Votes
      1
      Posts
      868
      Views

      No one has replied

    • Xml parsing using QXmlStreamReader
      General and Desktop • xml qxmlstreamreade premature end o • • Thom0801  

      2
      0
      Votes
      2
      Posts
      2186
      Views

      Hi and welcome to devnet, Your path to test.xml is relative so the file should be beside your executable. Currently your executable is located in a shadow build dir. So for your test you can use an absolute path or copy the file in the shadow build dir.
    • QtitanFastInfoset 1.0.0 (Binary XML or Zip-XML) has been released!
      Announcements • c++ xml qxmlstreamreade qxmlstreamwrite fastinfoset • • DevMachines  

      1
      0
      Votes
      1
      Posts
      722
      Views

      No one has replied

    • Iterate over XML with QXmlStreamReader
      General and Desktop • xml xml parsing qxmlstreamreade • • moravas  

      3
      0
      Votes
      3
      Posts
      1677
      Views

      Hi, thank you very much, it was a really nice help. (Additionally, my XML file wasn't well formatted, but it's fixed). But there is one thing that I didn't see, how can I relaize: how can I insert a node into an existing XML file? Regards, Norbert
    • QXmlStreamWriter overriding data in xml
      General and Desktop • xml serial • • Espresso  

      8
      0
      Votes
      8
      Posts
      3660
      Views

      Sorry, I misunderstood your problem. You don't need to keep all the data in-memory, you can read the file update the xml and write it again. On the other hand, you could also use a simple sqlite database to store your values and generate the xml only when needed.
    • How to read QString and bool values from xml ?
      General and Desktop • xml struct • • Ratzz  

      5
      0
      Votes
      5
      Posts
      6174
      Views

      @JohanSolo Thank you . I used index to read an array.
    • [SOLVED]How to write the model data to XML file ?
      General and Desktop • xml write • • Ratzz  

      5
      0
      Votes
      5
      Posts
      2696
      Views

      @NetZwerg I have set the values previously. if(var == "TR") { filter_values[row][column] = 0; }
    • Mensagem soap nao é enviada com codificacao correta
      Portuguese • xml socket soap • • Rodrigocg  

      3
      0
      Votes
      3
      Posts
      1279
      Views

      Obrigado pela resposta! vou testar hoje o que vc mandou e depois posto aqui se funcionou...
    • XmlListModel-XmlRole query problem
      QML and Qt Quick • qml listview qt 5.4 xml xml parsing xml model • • ceyhun  

      1
      0
      Votes
      1
      Posts
      795
      Views

      No one has replied

    • XML parser in QtScript
      Installation and Deployment • xml xml parsing qtscript • • fgdevel  

      1
      0
      Votes
      1
      Posts
      601
      Views

      No one has replied