XML plugin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mtyler
    Junior Member
    • Sep 2006
    • 4

    #46
    PLEASE NOTE:

    I hope that I have not overstepped my bounds by providing a modified version of xml.dll to this forum. The modification is based on the latest code base from "Instructor" and TinyXPath, but there are no promises of accuracy, reliability or safety, expressed or implied. Use at your own risk!

    It would be nice if "Instructor" integrated this addition into the next build of his XML Plugin, giving it full XPath capabilities.

    Comment

    • jeichhorn
      Junior Member
      • Jun 2005
      • 3

      #47
      I am trying to use the ${xml::GotoXPath} command added by mtyler.

      Here is my test.xml:

      code:
      <?xml version="1.0" encoding="utf-8" ?>
      <test>
      <c1>content1</c1>
      <c2>
      <c3>c3_content1</c3>
      <c3>c3_content2</c3>
      <c3>c3_content3</c3>
      </c2>
      </test>

      I am trying to select the element /test/c2/c3 with the content 'c2_content2'.

      When i use the xpath
      code:
      ${xml::GotoXPath} "//c3[text()='c3_content2']" $0
      the element is selected as expected, but when i use
      code:
      ${xml::GotoXPath} "/test/c2/c3[text()='c3_content2']" $0
      it does not find the element (result is -1).

      Do i use the GotoXPath function in a wrong way in my second example?

      Thanks for help.

      Jörg

      Comment

      • mtyler
        Junior Member
        • Sep 2006
        • 4

        #48
        The immediate workaround for your problem is to execute
        code:
        ${xml::RootElement} $1 $0
        after loading the document and before conducting any static XPath queries that begin with the root element. Any XPath that is based on the top level element will work, including yours.

        The way the TinyXML works is to have a node above the top level element for the document itself. From this node you can get the document name and access XML comments that are outside the scope of the top level element. The XML plugin maintains it state as the current or last node that was read. This enables you to jump around from a relative perspective. But, from a technical perspective, conducting a static XPath query from the document node will not work.

        I considered modifying the GotoXPath function to account for this, but I think that it will defeat the purpose of the document node. So use the workaround specified above or use the XPath query Descendant notation along with the root element (even though this is not entirely accurate; you should use xml::RootElement):
        code:
        //test/c2/c3[text()='c3_content2']
        The original GotoPath function looks for a leading slash in the path designation and moves the current node to the root element before it locates the desired element. This works well for this function because it is a simple navigation function. The TinyXPath library is a robust XPath processor that will not benefit from the same logic used by the GotoPath function. Therefore, the suggestions I made above should become the norm.

        As usual, I hope that this has helped. Feel free to ask for assistance. I am appreciative of all the great tools and technologies supported by this community.

        Comment

        • Instructor
          Major Dude
          • Jul 2004
          • 672

          #49
          Changed: Compiled statically without msvcrt.lib, now plugin work on Win95.
          Added: Integrated TinyXPath v1.2.4 (thanks mtyler).
          Added: ${xml::XPathString} -compute a string XPath expression.
          Added: ${xml::XPathNode} -compute a node XPath expression and goes to it.
          Added: ${xml::XPathAttribute} -compute an attribute XPath expression and goes to it.
          Added: ${xml::CurrentAttribute} -returns name and value of the current attribute.
          Updated: TinyXml to v2.5.1
          Updated: StackFunc.h to v2.0


          "XML" plugin v1.8

          Download from Wiki
          my functions

          Comment

          • rtpHarry
            Junior Member
            • Nov 2006
            • 5

            #50
            possible bug in system

            I almost abandoned this plugin yesterday when I was writing my installer. Now I have found a work around for it and I think its a great plugin again!

            The problem arose when I tried to open an xml file for the second time. The first time I loaded the file (through a function attached to a custom page) it worked fine with this code (as I see it used in the forums as well):

            PHP Code:
              ${xml::LoadFile"client-list.xml" $
            The second time I used it was in a Section (for the install files part) and it failed with -1 every time until I saw somebody suggest for a different problem to prepend $EXEDIR to the start which fixed it.

            PHP Code:
            ${xml::LoadFile"$EXEDIR\client-list.xml" $

            Comment

            • atul123
              Junior Member
              • Dec 2006
              • 1

              #51
              Where can I find examples of "How to use this XML plugin?"

              Comment

              • niklasu
                Junior Member
                • Jan 2007
                • 1

                #52
                XPathNode and XPathAttribute

                Originally posted by Instructor
                Added: ${xml::XPathString} -compute a string XPath expression.
                Added: ${xml::XPathNode} -compute a node XPath expression and goes to it.
                Added: ${xml::XPathAttribute} -compute an attribute XPath expression and goes to it.
                I'm trying to use XPathAttribute to change a setting in a web.config file, like this:
                PHP Code:
                ${xml::LoadFile"$INSTDIR\Web.config" $0
                ${xml::XPathAttribute"/configuration/appSettings/add[@key='EPsConnection']" $0
                ${xml::SetAttribute"value" "some value" $0
                ${xml::SaveFile"$INSTDIR\Web.config" $0
                ${xml::Unload
                But everytime the xml:XPathAttribute statement executes the installer crashes with the following message:
                code:

                Microsoft Visual C++ Runtime Library
                Assertion failed!

                Program: setup.exe
                File: tinyxml.cpp
                Line: 173

                Expression: node->GetDocument() == 0 || node->GetDocument() == this->GetDocument()

                (And I get the same error when using XPathNode too...)
                What am I doing wrong here?

                Comment

                • Instructor
                  Major Dude
                  • Jul 2004
                  • 672

                  #53
                  code:
                  ${xml::LoadFile} "$INSTDIRWeb.config" $0
                  ${xml::RootElement} $0 $1
                  ${xml::XPathAttribute} "/configuration/appSettings/add[@key='EPsConnection']" $0
                  ${xml::SetAttribute} "value" "some value" $0
                  ${xml::SaveFile} "$INSTDIRWeb.config" $0
                  ${xml::Unload}

                  my functions

                  Comment

                  • Yathosho
                    Forum King
                    • Jan 2002
                    • 3376

                    #54
                    could you put this on the wiki please?
                    NSIS IDE for Atom | NSIS for Visual Studio Code | NSIS for Sublime Text | NSIS.docset

                    Comment

                    • Commerzpunk
                      Junior Member
                      • Feb 2007
                      • 1

                      #55
                      Originally posted by Instructor
                      1. Not.
                      2. I'm not plaining this.

                      But you can use ${xml::CloneNode}

                      code:

                      Section
                      ${xml::LoadFile} "file.xml" $0
                      MessageBox MB_OK "xml::LoadFile$\n$$0=$0"

                      ${xml::GotoPath} "/" $0
                      MessageBox MB_OK "xml::GotoPath$\n$$0=$0"

                      ${xml::CloneNode} $R0
                      MessageBox MB_OK "xml::CloneNode$\n$$R0=$R0"

                      ${xml::Unload}


                      ${xml::LoadFile} "file2.xml" $0
                      MessageBox MB_OK "xml::LoadFile$\n$$0=$0"

                      ${xml::GotoPath} "/" $0
                      MessageBox MB_OK "xml::GotoPath$\n$$0=$0"

                      ${xml::InsertBeforeNode} "$R0" $0
                      MessageBox MB_OK "xml::InsertBeforeNode$\n$$0=$0"

                      ${xml::FreeNode} "$R0" $0
                      MessageBox MB_OK "xml::FreeNode$\n$$0=$0"

                      ${xml::SaveFile} "file2.xml" $0
                      MessageBox MB_OK "xml::SaveFile$\n$$0=$0"

                      ${xml::Unload}
                      SectionEnd


                      I really tried hard to get this working for me.
                      The installer always crashed, when I tried to "InsertBeforeNode".

                      Now, I used this code and changed it, had several hundered crashes.

                      Here is the working result (for me):

                      code:

                      ${xml::LoadFile} "file1.xml" $0
                      MessageBox MB_OK "xml::LoadFile$\n$$0=$0"

                      ${xml::GotoPath} "Root/I" $0
                      MessageBox MB_OK "xml::GotoPath$\n$$0=$0"

                      ${xml::CloneNode} $R0
                      MessageBox MB_OK "xml::CloneNode$\n$$R0=$R0"

                      ${xml::LoadFile} "file2.xml" $0
                      MessageBox MB_OK "xml::LoadFile$\n$$0=$0"

                      ${xml::RootElement} $0 $1 # THATS THE SOLUTION FOR NO CRASHING!
                      MessageBox MB_OK "xml::RootElement$\n$$0=$0"
                      MessageBox MB_OK "xml::RootElement$\n$$1=$1"

                      ${xml::GotoPath} "I" $0
                      MessageBox MB_OK "xml::GotoPath$\n$$0=$0"

                      ${xml::InsertBeforeNode} "$R0" $0
                      MessageBox MB_OK "xml::InsertBeforeNode$\n$$0=$0"

                      ${xml::SaveFile} "file2.xml" $0
                      MessageBox MB_OK "xml::SaveFile$\n$$0=$0"

                      ${xml::Unload}

                      Messageboxes are for information and debugging only, of course!

                      Greets,

                      HA
                      Last edited by Commerzpunk; 9 February 2007, 09:14.

                      Comment

                      • eafonsof
                        Junior Member
                        • May 2007
                        • 1

                        #56
                        Modify &quot;value&quot; attribute.

                        Hi there, I tried the following commands to modify the attribute named "value". It's not working as I expected. Does anybody know what's missing or wrong?
                        Thanks in advance.

                        ;Format of config file:
                        ;<?xml version="1.0" encoding="Windows-1252"?>
                        ;<configuration>
                        ; <appSettings>
                        ; <add key="key1" value="value1" />
                        ; <add key="key2" value="value2" />
                        ; <add key="key3" value="value3" />
                        ;
                        ; <!-- Some comments -->
                        ; <add key="key4" value="value4" />
                        ; </appSettings>
                        ;</configuration>

                        ${xml::LoadFile} "$configFile" $0
                        ${xml::RootElement} $0 $1
                        ${xml::XPathAttribute} "/configuration/appSettings/add[@key='${KEY4}']" $0
                        ${xml::SetAttribute} "value" "$newValue" $0
                        ${xml::SaveFile} "$configFile" $0
                        ${xml::Unload}

                        After this, the attribute "value" is set as an attribute of "<configuration" instead of the corresponding "<add" node.

                        i.e.
                        ;
                        ;<?xml version="1.0" encoding="Windows-1252"?>
                        ;<configuration value="new_value4">
                        ; <appSettings>
                        ; <add key="key1" value="value1" />
                        ; <add key="key2" value="value2" />
                        ; <add key="key3" value="value3" />
                        ;
                        ; <!-- Some comments -->
                        ; <add key="key4" value="value4" />
                        ; </appSettings>
                        ;</configuration>

                        Comment

                        • Instructor
                          Major Dude
                          • Jul 2004
                          • 672

                          #57
                          code:
                          ${xml::LoadFile} "$configFile" $0
                          ${xml::RootElement} $0 $1
                          ${xml::XPathNode} "/configuration/appSettings/add[@key='${KEY4}']" $0
                          ${xml::SetAttribute} "value" "$newValue" $0
                          ${xml::SaveFile} "$configFile" $0
                          ${xml::Unload}

                          my functions

                          Comment

                          • Instructor
                            Major Dude
                            • Jul 2004
                            • 672

                            #58
                            Updated: TinyXml to v2.5.3
                            Updated: TinyXPath to v1.3.0


                            "XML" plugin v1.9

                            Download from Wiki
                            my functions

                            Comment

                            • DrDan
                              Member
                              • Apr 2007
                              • 58

                              #59
                              Question about the plugin

                              I'm working on an installer that uses this plug-in. Now, depending on the contents in my XML I need to run an external progam (in fact another NSIS uninstaller) that will read in the XML file and make changes to it.

                              The steps I am following are:

                              1) Open the XML file in the main installer
                              2) Manipulate as required
                              3) Determine if an external uninstaller is required
                              4) If an external uninstaller is required, then save the XML file, run the external uninstaller, re-load the XML file and carry on.
                              5) If no external uninstaller is required, carry on.

                              My question is, in step 4, should I also unload the XML plug-in (i.e. call ${xml::Unload}) before running the external uninstaller?

                              Thanks.

                              Comment

                              • Wizarth
                                Junior Member
                                • Jul 2007
                                • 2

                                #60
                                SizeOf

                                Edit: Sorry, wrong thread.

                                Comment

                                Working...
                                X