Jump to content

XML joining


Recommended Posts

someone asked me to have a look at two xml files that they want as a single file

Now they are xml file but saved as a nzb and i was asked if there is a way to make both files work when used as a single file

 the 2 e.g. are below

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.nzbindex.com/nzb-1.0.dtd">
<!-- NZB Generated by NZBIndex -->
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file poster="fake@address.com (Psychopath)" date="1380635164" subject="New eBooks 29 September 2013 - &quot;9814-14074-31592.rar&quot; yEnc (1/1)">
<groups>
<group>alt.binaries.e-book</group>
<group>alt.binaries.e-book.flood</group>
</groups>
<segments>
<segment bytes="395417" number="1">524ad219$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
</segments>
</file>
</nzb>
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
<!-- NZB Generated by Binsearch.info (fcgi) -->
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">

<file poster="fake@address.com (Psychopath)" date="1380635157" subject="New eBooks 29 September 2013 - &quot;894-8564-6882.rar&quot; yEnc (1/1)">
<groups><group>alt.binaries.e-book</group></groups>
<segments>
<segment bytes="389484" number="1">524ad212$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
</segments>
</file>
</nzb>

now i see there are similarities and i tried a simple add this section to the other file but it doesnt work

<file poster="fake@address.com (Psychopath)" date="1380635157" subject="New eBooks 29 September 2013 - &quot;894-8564-6882.rar&quot; yEnc (1/1)">
<groups><group>alt.binaries.e-book</group></groups>
<segments>
<segment bytes="389484" number="1">524ad212$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
</segments>
</file>

Any suggestions?

There are websites that you can multi add several files into one but i cant figure out how

My eventual goal is to automate the joining of the files

Link to comment
Share on other sites

can you put here a schema file ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

which is what exactly?

these are all the files i have.

These are probably not xml in the purest sense as they relate to a different field

Edited by Chimaera
Link to comment
Share on other sites

The schema file sets up the formatting rules, etc.

You need to consider how the resulting combined file is going to be read/used.

If that doesn't matter, then you can mostly do what you want.

However, if you are expecting to use it as a nzb file for downloading etc, then you need to know the rules ... and you may not be able to combine them acceptably.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

simply

schema is a file like xml, but schema describe what you can do with xml

http://www.w3schools.com/schema/default.asp

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

The schema file sets up the formatting rules, etc.

You need to consider how the resulting combined file is going to be read/used.

If that doesn't matter, then you can mostly do what you want.

However, if you are expecting to use it as a nzb file for downloading etc, then you need to know the rules ... and you may not be able to combine them acceptably.

Yes that is exactly what it is for, the ones i have seen combined i think work because the same site generated them

But in this instance they are from different sites

simply

schema is a file like xml, but schema describe what you can do with xml

http://www.w3schools.com/schema/default.asp

Thx ill have a read

just compare the files joined together by some site and the files without joining and you see the trick?

I have done just that at the start when i was asked, but i cant see a difference that would stand out.

Other than the address here

<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.nzbindex.com/nzb-1.0.dtd">

<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">

I cant cycle through them that i know off

The double from the same site looks like this just as an example

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.nzbindex.com/nzb-1.0.dtd">
<!-- NZB Generated by NZBIndex -->
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file poster="fake@address.com (Psychopath)" date="1380635162" subject="New eBooks 29 September 2013 - &quot;98-3919-20011.rar&quot; yEnc (1/3)">
<groups>
<group>alt.binaries.e-book</group>
<group>alt.binaries.e-book.flood</group>
</groups>
<segments>
<segment bytes="397064" number="1">524ad217$0$58702$c3e8da3$12bcf670@news.astraweb.com</segment>
<segment bytes="397357" number="2">524ad21b$0$58702$c3e8da3$12bcf670@news.astraweb.com</segment>
<segment bytes="46444" number="3">524ad21e$0$58702$c3e8da3$12bcf670@news.astraweb.com</segment>
</segments>
</file>
<file poster="fake@address.com (Psychopath)" date="1380635161" subject="New eBooks 29 September 2013 - &quot;9172-5805-15030.rar&quot; yEnc (1/2)">
<groups>
<group>alt.binaries.e-book</group>
<group>alt.binaries.e-book.flood</group>
</groups>
<segments>
<segment bytes="397228" number="1">524ad215$1$58707$c3e8da3$12bcf670@news.astraweb.com</segment>
<segment bytes="60556" number="2">524ad218$0$58707$c3e8da3$12bcf670@news.astraweb.com</segment>
</segments>
</file>
</nzb>

Just found this format for the nzb

http://wiki.sabnzbd.org/nzb-specs

Edited by Chimaera
Link to comment
Share on other sites

$xml1 = @DesktopDir & "\1.xml"
$xml2 = @DesktopDir & "\2.xml"
$xmlCombined = @DesktopDir & "\Combo.xml"

$oXML1 = ObjCreate("Microsoft.XMLDOM")
$oXML2 = ObjCreate("Microsoft.XMLDOM")
$oXML1.Load($xml1)
$oXML2.Load($xml2)

$oParent = $oXML1.selectSingleNode( '//nzb' )
$oChildToAppend = $oXML2.selectSingleNode( '//file' )

$oParent.appendChild($oChildToAppend)
$oXML1.save($xmlCombined)

unfortunately, the only way I could get it to work was to make the following element a comment (both files):

<!--<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">-->

snippet will show the basics of using the xml-dom to query and append nodes

Output to 3rd file (assumption on my part...adding the file nodes inline with each other):

<?xml version="1.0" encoding="iso-8859-1"?>

<!--<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">-->

<!-- NZB Generated by NZBIndex -->

<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">

 <file poster="fake@address.com (Psychopath)" date="1380635164" subject="New eBooks 29 September 2013 - &quot;9814-14074-31592.rar&quot; yEnc (1/1)">

  <groups>

   <group>alt.binaries.e-book</group>

   <group>alt.binaries.e-book.flood</group>

  </groups>

  <segments>

   <segment bytes="395417" number="1">524ad219$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>

  </segments>

 </file>

 <file poster="fake@address.com (Psychopath)" date="1380635157" subject="New eBooks 29 September 2013 - &quot;894-8564-6882.rar&quot; yEnc (1/1)">

  <groups><group>alt.binaries.e-book</group></groups>

  <segments>

   <segment bytes="389484" number="1">524ad212$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>

  </segments>

 </file>

</nzb>

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thx for that i will do some tests later today and see if uploaded nzb can be done with that line commented out

It may not be a necessary line but ill check

Thx again to all

Link to comment
Share on other sites

Here, this one is better...it will grab all the <file> nodes, and append each to the new file.

It also comments, and then uncomments the DOCTYPE, so the XMLDom works, and then is in it's proper state at the end:

#include <File.au3>
$xml1 = @DesktopDir & "\1.xml"
$xml2 = @DesktopDir & "\2.xml"
$xmlCombined = @DesktopDir & "\Combo.xml"

$sXml1 = FileRead($xml1)
$sXml2 = FileRead($xml2)

$sXML1 = StringRegExpReplace($sXML1,"(<!DOCTYPE\s*nzb.*?>)","<!--\1-->" )
$sXML2 = StringRegExpReplace($sXML2,"(<!DOCTYPE\s*nzb.*?>)","<!--\1-->" )

$oXML1 = ObjCreate("Microsoft.XMLDOM")
$oXML2 = ObjCreate("Microsoft.XMLDOM")
$oXML1.LoadXML($sXML1)
$oXML2.LoadXML($sXML2)

$oParent = $oXML1.selectSingleNode( '//nzb' )
$oChildToAppendCol = $oXML2.selectNodes( '//file' )

For $oChildToAppend In $oChildToAppendCol

    $oParent.appendChild($oChildToAppend)
Next

$sComboXML = StringRegExpReplace($oXML1.xml,"(<!--)(<!DOCTYPE\s*nzb.*?>)(-->)","\2" )

_FileCreate($xmlCombined)
FileWrite($xmlCombined, $sComboXML)

Modified your second XML to include two Files (but any number will work)...sample output in combo file:

<?xml version="1.0"?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.nzbindex.com/nzb-1.0.dtd">
<!-- NZB Generated by NZBIndex -->
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
 <file poster="fake@address.com (Psychopath)" date="1380635164" subject="New eBooks 29 September 2013 - &quot;9814-14074-31592.rar&quot; yEnc (1/1)">
  <groups>
   <group>alt.binaries.e-book</group>
   <group>alt.binaries.e-book.flood</group>
  </groups>
  <segments>
   <segment bytes="395417" number="1">524ad219$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
  </segments>
 </file>
 <file poster="fake@address.com (Psychopath)" date="1380635157" subject="New eBooks 29 September 2013 - &quot;894-8564-6882.rar&quot; yEnc (1/1)">
  <groups><group>alt.binaries.e-book</group></groups>
  <segments>
   <segment bytes="389484" number="1">524ad212$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
  </segments>
 </file>
 <file poster="fake@address.com (Psychopath)" date="1380635157" subject="New eBooks 219 September 2013 - &quot;894-8564-6882.rar&quot; yEnc (1/1)">
  <groups><group>alt.binaries.e-book</group></groups>
  <segments>
   <segment bytes="389484" number="1">524ad212$0$1190$c3e8da3$50776f34@news.astraweb.com</segment>
  </segments>
 </file>
</nzb>
 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

You need to first un-comment these (if you were using my prior post, you modified the files from their true xml):

<!--<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">-->

back to

<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">

If you already did that, re-post the XML files you are using.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Been having a mess with this to make it do all the files in a folder and create one nzb

But its not filling in the xml file after it creates it?

#include <File.au3>
#include <Array.au3>
Local $sFiles = _NzbList(), $sComboXML
Local $xmlCombined = @ScriptDir & "\Combo.nzb"
    _FileCreate($xmlCombined)
    FileWrite($xmlCombined, $sComboXML)


Func _NzbList()
    Local $aNzbList = _FileListToArray(@ScriptDir, '*.nzb', 1)
    If @error Then
        Exit MsgBox(64, '', ' No Nzb Files Available ', 3)
    Else
        _ArrayDisplay($aNzbList)
        If IsArray($sFiles) Then
            For $i = 1 To $sFiles[0]
                $sXml1 = FileRead($sFiles[$i])
                $sXML1 = StringRegExpReplace($sXML1,"(<!DOCTYPE\s*nzb.*?>)","<!--\1-->" )
                $oXML1 = ObjCreate("Microsoft.XMLDOM")
                $oXML1.LoadXML($sXML1)
                $oParent = $oXML1.selectSingleNode( '//nzb' )
                $oChildToAppendCol = $oXML1.selectNodes( '//file' )
                For $oChildToAppend In $oChildToAppendCol
                    $oParent.appendChild($oChildToAppend)
                Next
                $sComboXML = StringRegExpReplace($oXML1.xml,"(<!--)(<!DOCTYPE\s*nzb.*?>)(-->)","\2" )
            Next
        EndIf
    EndIf
EndFunc   ;==>_NzbList()

Can someone point me in the right direction plz?

Edited by Chimaera
Link to comment
Share on other sites

Here ya go:

#include <File.au3>
#include <Array.au3>
$dir = @DesktopDir & "\XML"
$sComboFile = $dir & "\Combo.xml"
Local $aFiles[1]
$aFiles = _FileListToArray($dir,"*",1)

$oParentXML = ObjCreate("Microsoft.XMLDOM")
$oTempXML = ObjCreate("Microsoft.XMLDOM")

For $i = 1 To UBound($aFiles) - 1
    $sXML = FileRead($dir & "\" & $aFiles[$i])
    $sXML = StringRegExpReplace($sXML,"(<!DOCTYPE\s*nzb.*?>)","<!--\1-->" )

    If $i = 1 Then
        $oParentXML.LoadXML($sXML)
        $oParentNode = $oParentXML.selectSingleNode( '//nzb' )
        ConsoleWrite($oParentXML.xml & @CRLF)
    Else
        $oTempXML.LoadXML($sXML)
        $oTempNodeCol = $oTempXML.selectNodes( '//file' )
        For $oTempNode In $oTempNodeCol
            $oParentNode.appendChild($oTempNode)
        Next
    EndIf
Next

$sComboAll = StringRegExpReplace($oParentXML.xml,"(<!--)(<!DOCTYPE\s*nzb.*?>)(-->)","\2" )
_FileCreate($sComboFile)
FileWrite($sComboFile, $sComboAll)
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...