Results 1 to 4 of 4

Thread: XML text

  1. #1
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default XML text

    Hello, simple question, but if I am using QDom, and read an .XML file, if there is a line like:

    Qt Code:
    1. <title>Hello World</title>
    To copy to clipboard, switch view to plain text mode 

    how do I change it to something like:

    Qt Code:
    1. <title>Something New</title>
    To copy to clipboard, switch view to plain text mode 

    It should be simple, but I am having trouble figuring it out. I only want to change the text, nothing else, not the position in the QDomDocument. Does this make sense? (By the way, I am reading an .XML created by excel, and writing a program to insert data into the "excel" sheet)

    Thanks!

    Anna B

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML text

    Create a QDomText object using QDomDocument::createTextNode and replace the original text node with yours.

  3. The following user says thank you to wysota for this useful post:

    abrou (27th February 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: XML text

    Hello, thanks for your reply... I've been playing with it, and since I am also new to XML, I think I don't understand what it going on.

    Qt Code:
    1. QDomText newNode = doc.createTextNode("New Text");
    2. t = n.parentNode();
    3. QDomNode oldNode = t.replaceChild(newNode, n);
    To copy to clipboard, switch view to plain text mode 

    What happens is that it replaces the node with only
    "New Text", which can be seen below.

    Qt Code:
    1. <Row ss:Height="13.5" ss:AutoFitHeight="0">
    2. - <Cell ss:StyleID="s38">
    3. <Data ss:Type="String">Number of Quadrants</Data>
    4. </Cell>
    5. New Text //See? Not really a node, I don't think.
    6. - <Cell ss:StyleID="s40">
    7. <Data ss:Type="Number">14</Data>
    8. </Cell>
    9. </Row>
    To copy to clipboard, switch view to plain text mode 

    So, the replace works, my problem is that my node looks only like text..... as I said, I am new to XML...thanks!

    How can I make a node that looks like this:

    <Data ss:Type="String">New Text</Data>

  5. #4
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: XML text

    I figure it out, I missunderstood what a TextNode should look like, I always pictures it as part of a Node. I've fixed it, by refering to the second child of the node I originally replaced. FYI, I also had to change the attribute to read "String" instead of "Number" because excel didn't want to open it otherwise.

    Thanks!

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.