Jump to content
Sign in to follow this  
amakrkr

[Help]merging XML files

Recommended Posts

amakrkr

Delete it please.

I have reopended new thread.

Edited by amakrkr

Share this post


Link to post
Share on other sites
amakrkr

Ok here is the partial working script i made so far

#include<File.au3>
Local $original_file    =  FileOpen(@ScriptDir & "\" & "original.xml",0)   
local $original_file_link    =  @ScriptDir & "\" & "original.xml"       
local $i       =  1             
Local $user_file     = @ScriptDir & "\" & "created.xml"
Local $aArray  
Local $aRecords
_FileReadToArray($user_file, $aArray)
While 1
  
   Local $line = FileReadLine($original_file)  If @error = -1 Then ExitLoop
  
  
   if $line = '<Att08>' then
  
   local $inner_line = $i
  
   For $x = 1 To $aArray [0]
  
   
       $inner_line = $i + $x
  
   _FileWriteToLine($original_file_link ,$inner_line ,$aArray[$x])
  
   Next
   EndIf
  
   $i = $i+1
  
WEnd
FileClose($original_file)

Script works "fine" it inserts node to correct spot in target XML file but if i run script twice or more it just duplicates records under same node. What i would like is to delete node (with or with tags) and insert it again. So if user presses button twice it wont screw up XML.

Share this post


Link to post
Share on other sites
water

In the Examples Script forum there is a XMLDOMWrapper UDF which might help you.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

In the Examples Script forum there is a XMLDOMWrapper UDF which might help you.

I have tried that but i couldn't get it to work.

#include<File.au3>
#include<_XMLDomWrapper.au3>
Local $original_file    =  FileOpen(@ScriptDir & "\" & "original.xml",0)   
local $original_file_link    =  @ScriptDir & "\" & "original.xml"       
local $i       =  1             
Local $user_file     = @ScriptDir & "\" & "created.xml"
Local $aArray  
Local $aRecords
_FileReadToArray($user_file, $aArray)
While 1
  
   Local $line = FileReadLine($original_file)  If @error = -1 Then ExitLoop
  
  
   if $line = '<Att08>' then
  
   _XMLDeleteNode("/Targets/Att08")
  
   local $inner_line = $i
  
   For $x = 1 To $aArray [0]
  
   
       $inner_line = $i + $x
  
   _FileWriteToLine($original_file_link ,$inner_line ,$aArray[$x])
  
   Next
   EndIf
  
   $i = $i+1
  
WEnd
FileClose($original_file)

Share this post


Link to post
Share on other sites
water

I'm not very firm with XML but "couldn't get it to work" doesn't even help those who know more and are willing to help.

Please be more specific!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

Well abvove script compiles fine without any errors but NODE is still there. Function does not delete it.

Share this post


Link to post
Share on other sites
water

You have to do all processing of the XML file using functions from the UDF! _XMLFileOpen etc.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

Hello,

i am back with more question. So far i managed to open and properly read node i need and also delete it and insert new node.

#include<_XMLDomWrapper.au3>
#include<Array.au3>
$formed_xml       = @ScriptDir & "\" & "created.xml"
$origin_xml      =  @ScriptDir & "\" & "original.xml"       
_SetDebug (True)
_XMLFileOpen($origin_xml)
$re = _XMLGetChildNodes("/Targets/Att08")
_XMLDeleteNode("/Targets/Att08")
_XMLCreateChildNode("/Targets","Att08")
_XMLCreateChildWAttr("/Targets/Att08","Property","NAME","Inserted text 1")  ; tested insert of a node

I have fund a function _XMLCreateChildNode that will do just that but i have hard time figuring out parameters i needs to create XML node expecially in my case where

i have information stored in seperate xml file.

Edited by amakrkr

Share this post


Link to post
Share on other sites
water

If you have solved the problem, can you please post the result as a reference for future users?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

No i haven't solved it yet.

Read the above post.

Share this post


Link to post
Share on other sites
water

I see. You change the content of your posts :wacko:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

It doesn't look like you can work with multiple XMLS files at a time.

All functions use a single Global variable to access the XML file. So you need to process them in sequence. Open a file, grab all the needed information and store it in variables, open the second and copy the stored data.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

Yes i just figured this out ... i am just wondering how many lines can i store in a variable .... lets say my other xml is 10k lines long ?

Share this post


Link to post
Share on other sites
water

I think the only limit is memory. For easy processing decide if you want to store the XML file in a single variable or an array (using _FileReadToArray)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.