[C#] Help with XML Parsing

Discussion in 'Mixed Languages' started by CODYQX4, Aug 3, 2012.

  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,372
    150
    #1 CODYQX4, Aug 3, 2012
    Last edited by a moderator: Apr 20, 2017
    Code:
    <Products name = "Microsoft Office 2010">
    <Product name="Access">
    <Patches>
    <Patch RetailFile="AccessRWW.msi" VolumeFile="AccessWW.msi">
            <Retail Architecture = "x86"></Retail>
    <Volume Architecture = "x86"></Volume>
    <Retail Architecture = "x64"></Retail>
    <Volume Architecture = "x64"></Volume>
    </Patch>
    <Patch RetailFile="AccessRWW.xml" VolumeFile="AccessWW.xml">
    <Retail Architecture = "x86"></Retail>
    <Volume Architecture = "x86"></Volume>
    <Retail Architecture = "x64"></Retail>
    <Volume Architecture = "x64"></Volume>
    </Patch>
    <Patch RetailFile="AccRWW.cab" VolumeFile="AccWW.cab">
    <Retail Architecture = "x86"></Retail>
    <Volume Architecture = "x86"></Volume>
    <Retail Architecture = "x64"></Retail>
    <Volume Architecture = "x64"></Volume>
    </Patch>
    <Patch RetailFile="config.xml" VolumeFile="config.xml">
    <Retail Architecture = "x86"></Retail>
    <Volume Architecture = "x86"></Volume>
    <Retail Architecture = "x64"></Retail>
    <Volume Architecture = "x64"></Volume>
    </Patch>
    <Patch RetailFile="setup.xml" VolumeFile="setup.xml">
    <Retail Architecture = "x86"></Retail>
    <Volume Architecture = "x86"></Volume>
    <Retail Architecture = "x64"></Retail>
    <Volume Architecture = "x64"></Volume>
    </Patch>
    </Patches>
    </Product>
    </Products>
    I have made an XML File for Office Setup Patches, but I could use some help parsing it.

    I want to plug Architecture, Product Name, and License Channel into a function that will read this XML file and return a foreach-able custom class that holds the strings RetailFile, VolumeFile, and the value in the <Retail> or <Volume> tag matching the product.

    I use this to patch office setup, as the current code is a mess and won't scale well for Office 15.

    I know you can use XML methods, but am not sure how to do all this as the XML methods can be a pain to work with.

    I need to Base64 decode the value in <Retail> or <Volume> and store it in a byte array. This value is the patch file for that file, but that isn't what I need help with.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. wallace87000

    wallace87000 MDL Novice

    Jan 9, 2010
    6
    3
    0
    Try to use the VAKOS XML parser :

    codeproject.com/KB/XML/XML_Configuration_File

    You can easily create xml and load xml.

    Sorry I can't give you the exact link beacause I haven't 20 posts or greater...!!!o_O
     
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,372
    150
    I'm trying to avoid any extra code/libraries, as I know it can be done using the built in XML. I just haven't much time using them and have been too busy to bother with it right now.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    365
    3,190
    10
    Give me a day or two and I will write up something for you. I use XML a lot with my ISO verifier and other apps.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    365
    3,190
    10
    Sorry it took longer than I said. Here is an example and its source file. I included your xml file edited with numbers as an example. If you have any questions feel free to ask.
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,372
    150
    #6 CODYQX4, Aug 28, 2012
    Last edited: Aug 28, 2012
    (OP)
    Finally got it working. One thing is you have to reverse the indexes in one part of the code you wrote. The places where the numbers would be stored (Retail and Volume X86), apply to the current edition and make it the other channel, not reference the desired channel). Other than that I was able to tweak it and patch using my huge XML file.

    I may open source this section of my code if Stannieman wants it, but I'm still tweaking it.

    I'm definitely not looking forward to making Office 15 patches though. To do that, I must have each edition of Office, both VL and Retail, then have to create all the patches (which is tedious, but I may be able to write a better script), then have to put them in the XML.

    I store the patches in Base64, the patches are just xdeltas. MiscUtil library allows applying an xdelta but not creating one, so I have to use xdelta.exe from command line. I wrote a simple app that when run will read every file in the directory it is in and write their Base64 contents to BASE64_%FILENAME% where %FILENAME% is the file name.

    I'd then put those in the right places in the XML. The XML you wrote the code for only had Access and Word, with blank text, as the full file is 12MB and not easily posted for easy view (better people able to see the needed bits to write the code then have to DL a file).
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    365
    3,190
    10
    I am interested to see your code if you do make it open source. I am always looking for better ways to do things while coding. I'm glad I was able to start you in the right direction. Also I can't wait to use your program when it comes out. I am also going to be publishing a program soon called Windows Tech Console that will include a redesigned version of my RTM ISO Verifier, a FileHippo Installer Downloader and an Encryption Program.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,372
    150
    I'd say the one difficult thing about opening it is I've redesigned MTK to be way more modular, but some modules depend on others. So, say, it would be difficult to open source my Activation Backup code without opening 2 different modules it depends on to determine Office edition and

    But there are no more interdependencies, everything was previously pseudo-organized into classes, and I had to rip them apart, remove functions and rename constants just to use the same code on AutoKMS without including everything in MTK (which as you may know MTK is about 30MB, mostly resource crap like patches for Office Setup and the installers for AutoKMS/Tools).
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    365
    3,190
    10
    Well you could always create DLL files with the functions you want to keep closed source and then import them as a resource. Then you would use the import statement for the new class then just call the functions like normal in the main code. Creating dll files is nice as you can reuse the functions in them in the future with other programs you make.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...