Link to home
Start Free TrialLog in
Avatar of Jeremy Holbrook
Jeremy HolbrookFlag for United States of America

asked on

How to convert an XML Base64 file into a text document

I have a large .xml file that has base64 code in it.  I am not a programmer but I have a little bit of VBScript knowledge.  I am trying to figure out how to parse out the base64 code and convert it into a text document.  There is about 12,000 lines in the document.  Here is an example of what I have:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Dates>
  <Date DateId="162" Type="Text" Value="2016-11-15">
    <Revisions>
      <Revision Value="0">
        <Account Application="Info">
          <Pages PageCount="3">
            <Page>
              <PageNumber>1</PageNumber>
              <Content Encoding="Base64">DQogDQogDQo.....</Content>
               </Page>
                <Page>
                     <PageNumber>2</PageNumber>

Any help would be appreciated.

Thanks,

Jeremy
SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jeremy Holbrook

ASKER

Unfortunately the https://www.base64code.org can't handle but a small bit of information, and my document is 12,000 lines - otherwise yes this option would work.

The function looks very promising I am just not sure how to tie it into the vbscript.  
Here is what I have so far but its pulling the wrong info (I am getting everything but the base64) - I want it to pull the base64 code out of the xml and then convert it.

set objFSO=CreateObject("Scripting.FileSystemObject")

filename = "2016-11-15.xml"
outFile = "converted.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Set objFile = objFSO.CreateTextFile(outFile,True)

Do Until f.AtEndOfStream
  strLine=f.ReadLine
  If InStr(strLine, "DQo") = 0 Then
        objFile.Write strLine & vbCrLf
  End If
Loop

Function Base64Decode(ByVal vCode)
    Dim objDocument
    Dim objNode
    Dim b

        Set objDocument = CreateObject("MSXML2.DOMDocument")
        Set objNode = objDocument.createElement("document")
        objNode.DataType = "bin.base64"
   
    oNode.Text = vCode
    Base64Decode = StrConv(oNode.nodeTypedValue, vbUnicode)
End Function

objFile.Close
f.Close
Unfortunately the https://www.base64code.org can't handle but a small bit of information, and my document is 12,000 lines - otherwise yes this option would work

Wow, your lines must be quite long too, because I was able to encode and decode more than 1MB of data with no problem.

Anyway, if that didn't work, try this one...

http://www.freeformatter.com/base64-encoder.html

If you cut just the base64 content out and paste into it's own file, and then with the above site you can upload that file. I'm guessing this will mean that it can handle a bigger input size.
You pass the base64 string from the XML element to the function and it returns the decoded string
Thank you for your help.