Jump to content

XML DOM wrapper (COM)


eltorro
 Share

Recommended Posts

The XML-File looks like this:

<DreamSys><Tiff2PDF><Section name="1"><Tiff file="C:\Programme\ELOoffice\Postbox\Administrator\U_19143202_0000001.TIF"/><Tiff file="C:\Programme\ELOoffice\Postbox\Administrator\U_19143202_0000002.TIF"/></Section></Tiff2PDF></DreamSys>

Could anyone please help me?

I tried it in a hundred of different ways, but I just don't get it to work.

[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Link to comment
Share on other sites

The XML-File looks like this:

<DreamSys><Tiff2PDF><Section name="1"><Tiff file="C:\Programme\ELOoffice\Postbox\Administrator\U_19143202_0000001.TIF"/><Tiff file="C:\Programme\ELOoffice\Postbox\Administrator\U_19143202_0000002.TIF"/></Section></Tiff2PDF></DreamSys>

Could anyone please help me?

I tried it in a hundred of different ways, but I just don't get it to work.

This format is correct, it's just not indented properly.
Link to comment
Share on other sites

Will this ever get added to AutoIt? (UDFs)

I hope so. Pretty much every answer exists in this topic concerning XML, the same general questions keep getting asked over and over.

Link to comment
Share on other sites

Hello! I'm using your AWESOME UDF to read an RSS feed. But I have a question: Is there a way to parse CDATA? By default, that cause quotation marks and other punctuation to disappear, replaced by their decimal (I think) equivalent. Is there a possible fix for this? Thanks in advance!

Link to comment
Share on other sites

No hope, weaponx?

Umm well i'm pretty sure they are just html entities but I can't find a COM object / dll that can natively convert them to plain text. PHP and VB have functions that can decode these.

Link to comment
Share on other sites

  • 2 weeks later...
Link to comment
Share on other sites

Hi all,

Someone can help me?

I nead to update an XML file (the Windows Vista response file: Unattended.xml), but many test is unsucessful.

The xml code:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DiskConfiguration>
                <Disk>
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Size>20000</Size>
                            <Type>Primary</Type>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Active>true</Active>
                            <Extend>false</Extend>
                            <Format>NTFS</Format>
                            <Label>OS_Install</Label>
                            <Letter>C</Letter>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
                <WillShowUI>onerror</WillShowUI>
            </DiskConfiguration>
            <UserData>
                <ProductKey>
                    <Key>XXXXX-XXXXX-XXXXX-XXXXX-XXXXX</Key>
                    <WillShowUI>onerror</WillShowUI>
                </ProductKey>
                <AcceptEula>true</AcceptEula>
            </UserData>
            <ImageInstall>
                <OSImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>1</PartitionID>
                    </InstallTo>
                    <WillShowUI>onerror</WillShowUI>
                </OSImage>
            </ImageInstall>
            <UpgradeData>
                <Upgrade>true</Upgrade>
            </UpgradeData>
        </component>
        <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>en-us</UILanguage>
            </SetupUILanguage>
            <InputLocale>0409:00000409</InputLocale>
            <SystemLocale>en-us</SystemLocale>
            <UILanguage>en-us</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OEMInformation>
                <Manufacturer>&lt;company name&gt;</Manufacturer>
                <Model>&lt;computer model&gt;</Model>
                <SupportHours>&lt;support hours&gt;</SupportHours>
                <SupportPhone>&lt;phone number&gt;</SupportPhone>
            </OEMInformation>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="wim:c:/download/aik/install.wim#Windows Vista ULTIMATE" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>

I need to update the last "settings" section by adding this line "<ComputerName>MyComputer</ComputerName>" like this:

<settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ComputerName>MyComputer</ComputerName>
            <OEMInformation>
                <Manufacturer>&lt;company name&gt;</Manufacturer>
                <Model>&lt;computer model&gt;</Model>
                <SupportHours>&lt;support hours&gt;</SupportHours>
                <SupportPhone>&lt;phone number&gt;</SupportPhone>
            </OEMInformation>
        </component>
    </settings>

Thank you for your help,

Regards.

Link to comment
Share on other sites

  • 2 weeks later...

Since i can't write a line to a file in autoit easily i'm trying to work xml to be able to find a setting and change it.

----Start----

<?xml version="1.0" encoding="UTF-8"?>

<FILE>

<INFO Number="155367823"/>

<PROFILESET>

<PROFILE Label="Medal of Honor: Allied Assault">

<APPLICATION Label="mohaa.exe"/>

<APPLICATION Label="moh_breakthrough.exe"/>

<APPLICATION Label="moh_breakthrough_demo.exe"/>

<APPLICATION Label="moh_spearhead.exe"/>

<APPLICATION Label="moh_spearhead_demo.exe"/>

<APPLICATION Label="mohaademo.exe"/>

<PROPERTY Label="conformant_texture_clamp" Value="0x00000002" Default="0x00000002" Itemtype="predefined"/>

<PROPERTY Label="ogl_extension" Value="0x000011A8" Default="0x000011A8" Itemtype="predefined"/>

<PROPERTY Label="multichip_rendering_mode" Value="0x00000002" Default="0x00000002" Itemtype="predefined"/>

</PROFILE>

<PROFILE Label="Medal of Honor: Pacific Assault">

<APPLICATION Label="mohpa.exe"/>

<APPLICATION Label="mohpc.exe"/>

<PROPERTY Label="multichip_rendering_mode" Value="0x02402201" Default="0x02402201" Itemtype="predefined"/>

<PROPERTY Label="dyn_tiling_mode" Value="0x00000002" Default="0x00000002" Itemtype="predefined"/>

</PROFILE>

---break---

<PROFILE Label="Base Profile">

<PROPERTY Label="vsync_default" Value="0x08416747" Default="0x60925292"/>

</PROFILE>

---break---

<PROFILE Label="UAZ Racing 4x4">

<APPLICATION Label="4x4game.exe.exe"/>

<PROPERTY Label="multichip_rendering_mode" Value="0x02402005" Default="0x02402005" Itemtype="predefined"/>

</PROFILE>

<PROFILE Label="X-Motor Racing">

<APPLICATION Label="xmotorracing.exe"/>

<PROPERTY Label="multichip_rendering_mode" Value="0x02400005" Default="0x02400005" Itemtype="predefined"/>

</PROFILE>

</PROFILESET>

</FILE>

---end---

The part that i need to edit is the Value to the Property Label="vsync_default"

I've tried to read the property label, but have gotten no where near where i need to be.

Thanks

Link to comment
Share on other sites

  • 4 weeks later...

Can't get it to work correctly. I put this into Include folder and downloaded the example file (with gui controls). It saves the xml file just fine, but it can't read it. _XMLGetValue always returns -1 . I created simple script to test it. Obviously it didn't work:

#include <_XMLDomWrapper.au3>

$ret = _XMLFileOpen("settings.xml")
if $ret =0 then Exit
MsgBox(0, "test", _XMLGetValue("root/test/wellness"))

and xml:

<?xml version="1.0"?>
<root>
<test>
<wellness>100</wellness>
</test>
</root>
Edited by Asvarox
Link to comment
Share on other sites

I have this code which is based on your suggested method to generate XML posting with tree layout format. It works great so far on all my projects. However, recently one of my new project requires up to 6000+ no of postings. A performance issue is discovered which lead to scienificant slow down of runtime scripts. After I trace back, the root cause was due to the increment of processing time required by XML writing in each posting.

I have used a few _XMLDomWrapper methods in my libray. The timing issue mainly occur when I call _XMLCreateChildWAttr and _XMLCreateRootNodeWAttr.

Part of the code:

Func _TestLog_Message($s_title, $s_remarks, $s_picture)

$ROOT = "tree/"

; Record posting time
$result = _Date_Time_GetLocalTime()
$s_tCur = _Date_Time_SystemTimeToDateTimeStr($result)

; Define <item> Attribute Names
$ATTRIBS_Name = _ArrayCreate("id", "text", "im0", "im1", "im2", "child")   

; Define <userdata> attributes and values
$s_userdata_name = _ArrayCreate("type", "datetime", "remarks", "picture") 
$s_userdata_value = _ArrayCreate("message", $s_tCur ,$s_remarks, $s_picture)

; Icon image attributes for <item> posting
$s_im0 = "ms0.gif" ;icon for text
$s_im1 = "ms1.gif" ;icon for open node
$s_im2 = "ms2.gif" ;icon for close node
  
; Generate id for new posting
$s_xid = Number(_XMLGetAttrib("//udf", "xid"))   ;read <id> count from <udf id> attribute
$s_xid = StringFormat("%05s",$s_xid+1)    ; Generate unique "id" attribute from last posting entry

; Processing tree path layout
$s_xnode = _XMLGetAttrib("//udf", "xpath")   ;Read back xnode from temp <udf xpath> attribute
$s_xpath = $s_xnode & $s_xid
$SPLITPATH = StringSplit($s_xpath, "/")    ;[0]: numbe of elements, [1]: element[1]

; Reset element zero to zero for blank path (null counted as 1?)  
If $SPLITPATH[1] = "" Then  
  $SPLITPATH[0] = 0        ;indicate no element [0]=0
EndIf

; Generate XPATH formatting for nodes
For $X = 1 to $SPLITPATH[0]
  $SPLITPATH[$X] = StringFormat ( "item[@id='%s']", $SPLITPATH[$X] )  ;format xpath syntax for each node, @text = <item id>
Next

; Not valid if path is blank
If Not $SPLITPATH[0] = 0 Then
  ;--------------------------
  ; <item> attribute and child element
  ;--------------------------
  ; Generate folders to accomodate items path
  For $X = 1 to UBound($SPLITPATH) - 1
  
   $XPATH = $ROOT & _ArrayToString($SPLITPATH, "/", 1, $X) ;_ArrayToString = combine path items level by level
  
   ; Check if path exists
   If NOT IsArray(_XMLGetPath ($XPATH)) Then    ;_XMLGetPath = return path item into array from node in xpath
    If $X > 1 Then
     ; CHILD item
     $ATTRIBS_Value = _ArrayCreate($s_xid, $s_title, $s_im0, $s_im1, $s_im2, "0")
     _XMLCreateChildWAttr($ROOT & _ArrayToString($SPLITPATH, "/", 1, $X - 1), "item", $ATTRIBS_Name, $ATTRIBS_Value) ; node is "tree/" + xpath
    Else
     ; ROOT item
     $ATTRIBS_Value = _ArrayCreate($s_xid, $s_title, $s_im0, $s_im1, $s_im2, "0")
     _XMLCreateRootNodeWAttr("item", $ATTRIBS_Name, $ATTRIBS_Value)  ;Root node is "tree/item"
    EndIf
   EndIf

  Next 
  
  ;--------------------------
  ; <userdata> element
  ;--------------------------
  For $X = 0 to UBound($s_userdata_name) - 1
   _XMLCreateChildWAttr($XPATH, "userdata", "name", $s_userdata_name[$X], $s_userdata_value[$X])
  Next

EndIf

; Save UDF variable back to <udf> tag
_XMLSetAttrib("//udf", "xid", $s_xid)   ; save <id> count back to <udf id> attribute 

EndFunc

Example to call:

#include "_CTL_TestLog.au3"

$TempXML = @ScriptDir & "\example.xml"

_TestLog_Initiate($TempXML)

_TestLog_Folder_Open("Test Folder", "", "")

For $c=1 To 3000
$begin = TimerInit()
_TestLog_Message("Test is a test message", "", "")
$dif = TimerDiff($begin)
ToolTip("Posting Count " & $c & ", Duration: " & $dif, 400, 400, "Test Log Performance Testing", 1)
Sleep(3000)
Next

_TestLog_Folder_Close()

Is there anything wrong with the way I implement the code? Thanks in advance.

I have attached the generated XML, I only generated 1 level tree structure. But the increase in delay on every posting can be seen in the data. You can also see the delay when you run my Example.au3

<?xml version="1.0"?>
<tree id="0"><!--CTL AutoIT Test Log - Version 1.03-->

<udf xpath="" xid="03001"/>
<item id="00001" text="Test Folder" im0="ms0.gif" im1="ms1.gif" im2="ms2.gif" child="1" flag="0">
<userdata name="type">folder</userdata>
<userdata name="datetime">08/12/2009 15:14:47</userdata>
<userdata name="remarks"/>
<userdata name="picture"/>
<item id="00002" text="Test is a test message" im0="ms0.gif" im1="ms1.gif" im2="ms2.gif" child="0">
<userdata name="type">message</userdata>
<userdata name="datetime">08/12/2009 15:14:47</userdata>
<userdata name="remarks"/>
<userdata name="picture"/>
</item>
<item id="00003" text="Test is a test message" im0="ms0.gif" im1="ms1.gif" im2="ms2.gif" child="0">
<userdata name="type">message</userdata>
<userdata name="datetime">08/12/2009 15:14:50</userdata>
<userdata name="remarks"/>
<userdata name="picture"/>
</item>
<item id="00004" text="Test is a test message" im0="ms0.gif" im1="ms1.gif" im2="ms2.gif" child="0">
<userdata name="type">message</userdata>
<userdata name="datetime">08/12/2009 15:14:53</userdata>
<userdata name="remarks"/>
<userdata name="picture"/>
</item>
</item>
</tree>
Edited by VAG
Link to comment
Share on other sites

#include <_XMLDomWrapper.au3>
$sFile=@ScriptDir&"\dd.xml"
writexml()
readxml()

Func writexml()
    _XMLCreateFile($sFile, "config", True)
    _XMLFileOpen($sFile)
    _XMLCreateRootChild("option")
    _XMLCreateChildWAttr("config/option","update","auto","false")
    _XMLCreateChildWAttr("config/option","recordlastplaypos","auto","true")
    _XMLCreateChildNode("config/option","boxopen")
    _XMLCreateAttrib("config/option/boxopen","bystorm","false")
    _XMLCreateAttrib("config/option/boxopen","bylive","false")
EndFunc
Func readxml()
    _XMLFileOpen($sFile)
    MsgBox(0,"",_XMLGetAttrib("config/option/update","auto"))
    MsgBox(0,"",_XMLGetAttrib("config/option/recordlastplaypos","auto"))
    MsgBox(0,"",_XMLGetAttrib("config/option/boxopen","bylive"))
EndFunc

the _XMLGetAttrib() cann't get the right result,please fix it

Link to comment
Share on other sites

Contents of the XML would maybe help... Actually, it is needed. Post it.

As far as I can work out, the functions are more than fine. Its probably (more likely) your code...

Link to comment
Share on other sites

Contents of the XML would maybe help... Actually, it is needed. Post it.

As far as I can work out, the functions are more than fine. Its probably (more likely) your code...

I have updated my post with the generated XML. The delays can seen more obviously in the attached file. It can also be seen by running Example.au3 in my attached scripts.

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...