Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to insert a child element in an existing element
Forum Updated to NodeBB v4.3 + New Features

How to insert a child element in an existing element

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developer
    wrote on last edited by
    #1

    I want to insert an child element in an existing element in an existing text file. my file is like this:
    @<?xml version="1.0" encoding="UTF-8"?>
    <passwords name="shubham the ultimate champion">
    <account>
    <name>shubham maheshwari</name>
    <password>sdfsdf</password>
    <account_type>forum</account_type>
    <account_name>shubham1</account_name>
    <home_page>ohloglsfosdf</home_page>
    </account>
    <account>
    <name>siddharth maheshwari</name>
    <password>adfadf</password>
    <account_type>devnet</account_type>
    <account_name>sidharth1</account_name>
    <home_page>jkjskdfjdfsk</home_page>
    </account>
    </passwords>@
    I have tried many things i want the best easy simple and fast way to insert a new tag named "account" in "passwords"

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      Hi, ~developer!

      Why can't you fetch DOM and append dom child into passwords with standart QtXml module's functional?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        developer
        wrote on last edited by
        #3

        @tucnak please a small exmaple code or hint or classes

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tucnak
          wrote on last edited by
          #4

          [quote author="developer" date="1352531950"]@tucnak please a small exmaple code or hint or classes[/quote]

          Create "QDomDocument":http://qt-project.org/doc/qt-5.0/qdomdocument.html] refering to the file which has your XML.

          Parse xml as DOM tree

          Insert "QDomNode":http://qt-project.org/doc/qt-5.0/qdomnode.html after another node you need to find

          1 Reply Last reply
          0
          • D Offline
            D Offline
            developer
            wrote on last edited by
            #5

            ok i have tried a lot please tell me how to parase xml as dom tree

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tucnak
              wrote on last edited by
              #6

              Use QDomNode nextSibling() while nextSibling's QDomNode will have the tag name 'passwords' and append to it your QDomNode.

              References:
              http://qt-project.org/doc/qt-4.8/qdomdocument.html#createElement
              http://qt-project.org/doc/qt-4.8/qdomdocument.html#toString
              http://doc.qt.digia.com/qt/qdomnode.html#appendChild
              http://doc.qt.digia.com/qt/qdomnode.html#nextSibling

              And read a bit about QtXml.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved