Announcement

Collapse
No announcement yet.

How to using insert XML to XML file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to using insert XML to XML file

    How to solve this problem?
    My Default and load XML file is:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <products> 
      <product> 
        <course id="SK-ENG-L1-NA-PE-NA-NA-Y-3.7.1.0.r29" levelIndex="1" titleKey="PE_ENG_1_course_title" language="en-US" resource="68cebc9173417426b9c277770e7aca3cc4847a03" encrypted="true"> 
        <installed>false</installed> 
    </course> 
    <activations> 
          <activation> 
            <productID>SK-ENG-L1-NA-PE-NA-NA-Y-3</productID> 
            <activationID/> 
            <deactivationID/> 
            <titleKey>PE_ENG_1_course_title</titleKey> 
            <courses> 
              <course>SK-ENG-L1-NA-PE-NA-NA-Y-3</course> 
            </courses> 
          </activation>
    <activations>
       </product>
    </products>
    will insert XML file is:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <course id="SK-ENG-L2-NA-PE-NA-NA-Y-3.7.1.0.r29" levelIndex="2" titleKey="PE_ENG_2_course_title" language="en-US" resource="f626f5187b2ba7417f822324f964238fb6c16719" encrypted="true">  
     <installed>false</installed> 
    </course> 
    <activations>
          <activation> 
            <productID>SK-ENG-L2-NA-PE-NA-NA-Y-3</productID> 
            <activationID/> 
            <deactivationID/> 
            <titleKey>PE_ENG_2_course_title</titleKey> 
            <courses> 
              <course>SK-ENG-L2-NA-PE-NA-NA-Y-3</course> 
            </courses> 
          </activation> 
    </activations>
    Result XML file is:
    Code:
    </course> 
    <course id="SK-ENG-L2-NA-PE-NA-NA-Y-3.7.1.0.r29" levelIndex="2" titleKey="PE_ENG_2_course_title" language="en-US" resource="f626f5187b2ba7417f822324f964238fb6c16719" encrypted="true">  
     <installed>false</installed> 
    </course> 
    <activations> 
          <activation> 
            <productID>SK-ENG-L1-NA-PE-NA-NA-Y-3</productID> 
            <activationID/> 
            <deactivationID/> 
            <titleKey>PE_ENG_1_course_title</titleKey> 
            <courses> 
              <course>SK-ENG-L1-NA-PE-NA-NA-Y-3</course> 
            </courses> 
          </activation> 
    <activation> 
            <productID>SK-ENG-L2-NA-PE-NA-NA-Y-3</productID> 
            <activationID/> 
            <deactivationID/> 
            <titleKey>PE_ENG_2_course_title</titleKey> 
            <courses> 
              <course>SK-ENG-L2-NA-PE-NA-NA-Y-3</course> 
            </courses> 
          </activation> 
    </activations> 
      </product> 
    </products>

    I tried:
    Code:
    XML.Load(SessionVar.Expand("%WindowsFolder%\\01.xml"));
    XML.InsertXML("products/product/course", "<course id=\"SK-ENG-L2-NA-PE-NA-NA-Y-3.7.1.0.r29\" levelIndex=\"2\" titleKey=\"PE_ENG_2_course_title\" language=\"en-US\" resource=\"f626f5187b2ba7417f822324f964238fb6c16719\" encrypted=\"true\">\r\n<installed>false</installed>\r\n</course>", XML.INSERT_AFTER);
    XML.InsertXML("products/product/activations/activation", "<activation>\r\n<productID>SK-ENG-L2-NA-PE-NA-NA-Y-3</productID>\r\n<activationID/>\r\n<deactivationID/>\r\n<titleKey>PE_ENG_2_course_title</titleKey>\r\n<courses>\r\n<course>SK-ENG-L2-NA-PE-NA-NA-Y-3</course>\r\n</courses>\r\n</activation>", XML.INSERT_AFTER);
    XML.Save(SessionVar.Expand("%WindowsFolder%\\rsapp3\\products1.xml"));
    But not changed 01.xml file

  • #2
    1. You cannot manipulate UTF-8 encoded text files with Lua, and they may not load properly.
    2. There is an <activations> instead of </activations> in your initial XML, causing a nesting error and resulting in an error during load.
    3. Use proper error checking to make your life easier.


    Ulrich
    Last edited by Ulrich; 04-01-2014, 07:03 PM.

    Comment


    • #3
      How to error checking ?

      Comment


      • #4
        How to properly check for errors is shown extensively in the documentation.

        Ulrich

        Comment


        • #5
          I tried:
          Code:
          XML.Load(SessionVar.Expand("%WindowsFolder%\\01.xml"));
          -- Check whether an error occurred
          error = Application.GetLastError();
          -- If no errors occurred...
          if (error == XML.OK) then
              -- get the current XML document as a string
              strXML = XML.GetXML();
              
              -- if no errors occurred, display the XML in a popup dialog
              error = Application.GetLastError();
              if (error == XML.OK) then
                  Dialog.Message("XML contents",strXML);
              else
                  Dialog.Message("Error", _tblErrorMessages[error]);
              end
          else    
              Dialog.Message("Error", _tblErrorMessages[error]);
          end
          XML.InsertXML("products/product/course", "<course id=\"SK-ENG-L2-NA-PE-NA-NA-Y-3.7.1.0.r29\" levelIndex=\"2\" titleKey=\"PE_ENG_2_course_title\" language=\"en-US\" resource=\"f626f5187b2ba7417f822324f964238fb6c16719\" encrypted=\"true\">\r\n<installed>false</installed>\r\n</course>", XML.INSERT_AFTER);
          XML.InsertXML("products/product/activations/activation", "<activation>\r\n<productID>SK-ENG-L2-NA-PE-NA-NA-Y-3</productID>\r\n<activationID/>\r\n<deactivationID/>\r\n<titleKey>PE_ENG_2_course_title</titleKey>\r\n<courses>\r\n<course>SK-ENG-L2-NA-PE-NA-NA-Y-3</course>\r\n</courses>\r\n</activation>", XML.INSERT_AFTER);
          XML.Save(SessionVar.Expand("%WindowsFolder%\\rsapp3\\products1.xml"));
          But not changed 01.xml file saved products1.xml and no message error checking. How to solve this problem Help me

          Comment

          Working...
          X