Sign in to follow this  
Followers 0
ManelRodero

How to modify an XML file?

3 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm trying to use _XMLDomWrapper for modifying a XML configuration file for Windows Media Encoder without success. The XML is the following one:

<?xml version="1.0"?>

<WMEncoder major_version="9"
    minor_version="0"
    Name="WMEncoder7001"
    SynchroniesOperation="0" >
    <Description Author="STR_AUTHOR"
        Title="STR_TITLE"
        Copyright="STR_COPYRIGHT"
        Description="STR_DESCRIPTION" />
    <SourceGroups >
        <SourceGroup Name="ExtronScaler" >
            <Source Type="WMENC_VIDEO"
                Scheme="screencap"
                PixelAspectRatioX="1"
                PixelAspectRatioY="1" >
                <UserData >
                    <WMENC_STRING Name="WindowTitle" />
                    <WMENC_LONG Name="CaptureWindow" Value="0" />
                    <WMENC_LONG Name="Left" Value="0" />
                    <WMENC_LONG Name="Top" Value="0" />
                    <WMENC_LONG Name="Right" Value="1680" />
                    <WMENC_LONG Name="Bottom" Value="1050" />
                    <WMENC_DOUBLE Name="FrameInterval" Value="0.0400" />
                    <WMENC_BOOL Name="FlashRect" Value="no" />
                    <WMENC_BOOL Name="Screen" Value="yes" />
                </UserData>

            </Source>

            <Source Type="WMENC_AUDIO"
                Scheme="device"
                InputSource="Default_Audio_Device" >
                <UserData >
                    <WMENC_BOOL Name="UseRecordQueue" Value="no" />
                    <WMENC_STRING Name="RecordTempPath" Value="C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp\" />
                    <WMENC_STRING Name="MinimumDiskSpace" Value="10485760" />
                    <WMENC_BOOL Name="SaveToDiskOnlyDuringCapture" Value="no" />
                </UserData>

            </Source>

            <EncoderProfile id="Streaming FIB Encoding" />
            <UserData >
                <WMENC_LONG Name="Video0\CropMethod" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomT" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomL" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomR" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomB" Value="0" />
            </UserData>

        </SourceGroup>

    </SourceGroups>

    <File LocalFileName="D:\VIDEOS\AAAAMMDD_HHMM_STR_TITLE_FILE.wmv" />
    <Broadcast Http="8080"
        PublishServer="wmserver"
        PublishingPoint="sala-actes"
        PublishPort="80" />
    <WMEncoder_Profile id="Streaming FIB Encoding" >
    <![CDATA[        <profile version="589824" 
             storageformat="1" 
             name="Streaming FIB Encoding" 
             description="
"> 
                   <streamconfig majortype="{73647561-0000-0010-8000-00AA00389B71}" 
                   streamnumber="1" 
                   streamname="Audio Stream" 
                   inputname="Audio40a" 
                   bitrate="128016" 
                   bufferwindow="5000" 
                   reliabletransport="0" 
                   decodercomplexity="" 
                   rfc1766langid="es" 
 > 
             <wmmediatype subtype="{00000161-0000-0010-8000-00AA00389B71}"  
                   bfixedsizesamples="1" 
                   btemporalcompression="0" 
                   lsamplesize="2731"> 
           <waveformatex wFormatTag="353" 
                         nChannels="2" 
                         nSamplesPerSec="48000" 
                         nAvgBytesPerSec="16002" 
                         nBlockAlign="2731" 
                         wBitsPerSample="16" 
                         codecdata="008800000F0000000000"/> 
            </wmmediatype>
            </streamconfig>
                   <streamconfig majortype="{73646976-0000-0010-8000-00AA00389B71}" 
                   streamnumber="2" 
                   streamname="Video Stream" 
                   inputname="Video40a" 
                   bitrate="682000" 
                   bufferwindow="5000" 
                   reliabletransport="0" 
                   decodercomplexity="AU" 
                   rfc1766langid="es" 
 > 
                     <videomediaprops maxkeyframespacing="40000000" 
                                     quality="90"/> 
             <wmmediatype subtype="{33564D57-0000-0010-8000-00AA00389B71}"  
                   bfixedsizesamples="0" 
                   btemporalcompression="1" 
                   lsamplesize="0"> 
       <videoinfoheader dwbitrate="682000" 
                        dwbiterrorrate="0" 
                        avgtimeperframe="400000"> 
        <rcsource left="0" 
                  top="0" 
                  right="0" 
                  bottom="0"/> 
        <rctarget left="0" 
                  top="0" 
                  right="0" 
                  bottom="0"/> 
            <bitmapinfoheader biwidth="0" 
                              biheight="0" 
                              biplanes="1" 
                              bibitcount="24" 
                              bicompression="WMV3" 
                              bisizeimage="0" 
                              bixpelspermeter="0" 
                              biypelspermeter="0" 
                              biclrused="0" 
                              biclrimportant="0"/> 
       </videoinfoheader>
            </wmmediatype>
            </streamconfig>
    </profile> 
    ]]>
    </WMEncoder_Profile>

    <UserData >
        <WMENC_LONG Name="Encoding\Dest" Value="2" />
        <WMENC_LONG Name="Encoding\Bitrate0\Video0\CustomW" Value="0" />
        <WMENC_LONG Name="Encoding\Bitrate0\Video0\CustomH" Value="0" />
        <WMENC_LONG Name="Encoding\LocalComplexity" Value="-1" />
        <WMENC_LONG Name="Encoding\BroadcastComplexity" Value="-1" />
        <WMENC_STRING Name="Encoding\Audio0" />
        <WMENC_STRING Name="Encoding\Video0" />
        <WMENC_STRING Name="Encoding\Script0" />
    </UserData>

</WMEncoder>

How can I do the following:

1) Change the value of 'Author' attribute in 'Description' section (this section is always in the XML file):

<Description Author="STR_AUTHOR"
        Title="STR_TITLE"
        Copyright="STR_COPYRIGHT"
        Description="STR_DESCRIPTION" />

2) Add some nodes like these ones (the section 'File' and the Section 'Broadcast' aren't in the file initially but must be added by code and independently):

<File LocalFileName="D:\VIDEOS\AAAAMMDD_HHMM_STR_TITLE_FILE.wmv" />
    <Broadcast Http="8080"
        PublishServer="wmserver"
        PublishingPoint="sala-actes"
        PublishPort="80" />

I've tried the following code:

Dim $attribs = _ArrayCreate("Http","PublishServer","PublishingPoint","PublishPort")
    Dim $values = _ArrayCreate("8080","wmserver","sala-actes","80")
    _XMLCreateRootNodeWAttr ( 'Broadcast', $attribs, $values)
    ConsoleWrite("After Create RootNode" & @LF)

and I get the node inserted in the XML but the program exits with an error and the ConsoleWrite code isn't executed:

-1
D:\AutoIt\_XMLDomWrapper.au3 (2011) : ==> Variable used without being declared.:
$objFormat = $objDoc.createTextNode(@CR)
^ ERROR

Any idea about what's the problem with the CreateRootNodeWAttr function?

Thank you!

PS: The code inside _XMLDomWrapper with the error is this one:

Func _AddFormat($objDoc, $objParent = "")
    If $fADDFORMATTING = True Then
        If Not IsObj($objDoc) Then
            _XMLError("No object passed to function _XMLAddFormat")
            Return SetError(1, 30, -1)
        EndIf
        $objFormat = $objDoc.createTextNode(@CR)
        If IsObj($objParent) Then
            $objParent.appendChild($objFormat)
        Else
            $objDoc.documentElement.appendChild($objFormat)
        EndIf
        _XMLSaveDoc($strFile)
    EndIf
    Return 1
EndFunc   ;==>_AddFormat
Edited by ManelRodero

Share this post


Link to post
Share on other sites



#include <_XMLDomWrapper.au3>
#include <Array.au3>

Global Const $sFile = @ScriptDir & '\file.xml'

If _XMLFileOpen($sFile) = 1 Then
    _XMLSetAttrib('//Description', 'Author', 'Value')
    
    Local $aAttr = StringSplit('Http|PublishServer|PublishingPoint|PublishPort', '|')
    Local $aValues = StringSplit('8080|wmserver|sala-actes|80', '|')
    
    Local $oNodeBefore = $objDoc.createNode($NODE_ELEMENT, 'File', '')
    Local $oNodeAfter = $objDoc.selectSingleNode('WMEncoder/WMEncoder_Profile')
    
    $oNodeAfter.parentNode.insertBefore($oNodeBefore, $oNodeAfter)
    $oNodeBefore.setAttribute('LocalFileName', 'D:\VIDEOS\AAAAMMDD_STR_TITLE_FILE.wmv')
    
    $oNodeBefore = $objDoc.createNode($NODE_ELEMENT, 'Broadcast', '')
    $oNodeAfter.parentNode.insertBefore($oNodeBefore, $oNodeAfter)
    
    
    For $i = 1 To $aAttr[0]
        $oNodeBefore.setAttribute($aAttr[$i], $aValues[$i])
    Next
    
    $objDoc.save($sFile)
EndIf

Share this post


Link to post
Share on other sites

x Authenticy:

Hello,

Thank you very much for your code. It works wonderfully!

But, I don't understand why we can't use XML DOM Wrapper functions defined in the library and we need to go through coding at "low level" (using $objDoc, etc.) for inserting nodes.

Is a problem of the library? Is a better approach to solve this kind of problems?

Only curiosity ...

Thanks again!

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  
Followers 0