Uniface User Forum

 View Only
Expand all | Collapse all

scan for NUL character in XML file

  • 1.  scan for NUL character in XML file

    Posted 04-09-2021 17:44

    Hi, I am facing an issue with generated xml file. Sometimes randomly it contains NUL character instead of valid data. I would like to scan the file to confirm whether the file is correct (without the NUL) or corrupted (with NUL). But I don't know how to handle it in Uniface.  

    When I do fileload/raw of the file above and filedump/raw then in the new file I see something like this ! instead of NUL. 

    Does anyone have a clue how to recognize the NUL character in the XML? I would like to avoid to use fileload/filedump because of performance reasons.




  • 2.  RE: scan for NUL character in XML file

    Posted 04-10-2021 07:22

    Hi Jozef,

    IMHO the first choice is to ask to your XML provider to clean up the file at the origin; if this option it is not available for whatever reason you should clean it by yourself before loading it.

    There are tons of HTML/XHTML/XML utilities available to clean it up: the one I use and like the most is "tidy". This "grandaddy of all HTML tools" implements a lot of different options: try to start it up with "tidy --help" to read its long long list. You can find sources HERE while latest official compiled binaries can be downloaded HERE. I am actually using version 5.7.17 downloaded somewhere either 32bit and 64bit but I do not remember the original page, sorry. Latest version available as sources is 5.7.28.
    I am using it as an external command (it's quite fast!); for performance reason I would prefer to have a signature directly using libtidy but up to now I never really had the opportunity to implement it.

    Hope it helps.

    Regards,
    Gianni



  • 3.  RE: scan for NUL character in XML file

    Posted 04-12-2021 21:32

    Hi Gianni, thanks for your answer, but actually our app is the XML provider (our app is generating the xml file).



  • 4.  RE: scan for NUL character in XML file

    Posted 04-13-2021 05:56

    Hi Jozef,

    that's make things easier... 🙂

    Gianni



  • 5.  RE: scan for NUL character in XML file

    Posted 04-13-2021 11:41

    Hi Gianni, yes, but how does it make things easier? You advice to use the tool for xml inspection like "tidy". But how can I use it inside of Uniface without the need to install it at the customer environment?

    Jozef



  • 6.  RE: scan for NUL character in XML file

    Posted 04-13-2021 17:59

    Hi Josef,

    tidy it is a simple utility which does NOT need any real installation. You can find it on the internet in two ways: exe + dll or just everything in an exe file, depending from the way used to generate it.
    I usually collect all these utilities in a .\bin directory under the Uniface application tree, starting them from there.

    Regards,
    Gianni



  • 7.  RE: scan for NUL character in XML file

    Posted 04-14-2021 06:55

    Hi Gianni, I did download and tried the help of the tidy tool but I don't know which command is possible to use for scanning (searching) the NUL character in the xml file. Do you know which one is suitable?

    BR, Jozef



  • 8.  RE: scan for NUL character in XML file

    Posted 04-14-2021 10:20

    Hi Jozef,

    Based on your previous answer, considering your application is the XML generator I was supposing you would prefer to clean the file at the origin rather then in a later stage, it is better IMHO as already told...however:

    tidy as well as all others HTML/XHTML/XML utilities do NOT have such low level operation like you are asking for; their implementation is at higher level, so with these utilities you should look for and verify some sort of "clean"ing action.

    If you prefer to use a very simple filter to strip all NUL values from your XML (as well as any other "dirty" char), Uniface has $replace() but I do not think it works with NUL values, being that byte the string endpoint for all strings in memory (let's give it a try however!). As an alternative I would suggest you another external utilities like "tr" directly available in Unix/Linux and in Windows environment being part of GnuWin32. Almost all utilities being part of GnuWin32 does NOT require a real installation.

    Regards,
    Gianni



  • 9.  RE: scan for NUL character in XML file

    Posted 04-14-2021 20:36

    Hi Jozef,

    $replace() works!

    Regards,
    Gianni



  • 10.  RE: scan for NUL character in XML file

    Posted 04-15-2021 06:51

    Hi Gianni, how did you test it? Could you please send me the piece of code?

    Thx.

    Regards,

    Jozef



  • 11.  RE: scan for NUL character in XML file

    Posted 04-12-2021 21:31

    Hi Gianni, thanks for your answer, but actually our app is the XML provider (our app is generating the xml file).




  • 12.  RE: scan for NUL character in XML file
    Best Answer

    Posted 04-15-2021 12:47

    Hi Jozef,

    my doubts about $replace() were definitively wrong...

    I have created a simple button having into <DETAIL> the following code:

    variables
        string    cCR
        string    vTextIni, vTextFin
        raw        vRaw, vRawClean, vMultiZeroBin, vSingleZeroBin
    endvariables
    ; Initialize few variables...
    cCR = "%%^"
    vTextIni = $concat("It's a long way to Tipperary,", cCR, "It's a long way to go.", cCR, $concat("It's a long way to Tipperary", cCR, "To the sweetest girl I know!", cCR))
    vTextFin = $concat("Goodbye Piccadilly,", cCR, "Farewell Leicester Square!", cCR, $concat("It's a long long way to Tipperary,", cCR, "But my heart's right there.", cCR))
    vMultiZeroBin = $decode("HEX", "000000000000000000000000")
    ; Build a RAW string simulating what Josef has loaded as XML
    vRaw = $concat(vTextIni, vMultiZeroBin, vMultiZeroBin, cCR, vTextFin)
    ; Dump it to disk to be read later on with Notepad++
    filedump/raw vRaw, "myFileRaw.txt"
    ; ========== =========== =========== =========== =========== ===========
    ; Initialize single binary zero
    vSingleZeroBin = $decode("HEX", "00")
    ; Replace binary zero in the raw string
    vRawClean = $replace(vRaw, 1, vSingleZeroBin, "", -1)
    ; Dump the result to disk to be read with Notepad++
    filedump/raw vRawClean, "myFileRawClean.txt"
    ; Let's clean empty lines too...
    vRawClean = $replace(vRawClean, 1, $concat(cCR, cCR), cCR, -1)
    filedump/raw vRawClean, "myFileRawNoEmptyLines.txt"
    ; ========== =========== =========== =========== =========== ===========
    message/info "Done!"

    After executing open into Notepad++ the three files dumped to disks.

    ...et voilà!

    Regards,
    Gianni



  • 13.  RE: scan for NUL character in XML file

    Posted 04-19-2021 15:11

    Hi Gianni, thanks for your help. The example code you sent, helped me. Especially the :

    vSingleZeroBin = $decode("HEX", "00")
    ; Replace binary zero in the raw string
    vRawClean = $replace(vRaw, 1, vSingleZeroBin, "", -1)


    I did not know that I can simulate the NUL char with the decode statement. That is exactly what I was looking for.