Jump to content

Recommended Posts

Posted

there is problem with 

appendChild($oProcessingInstruction)

I'll investigate ti more today.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

here is fix.

Func _XMLCreateFile($sXML_FileFullPath, $sRoot, $bUTF8 = False, $iDOM_Version = Default)
    ; Error handler, automatic cleanup at end of function
    Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_UserFunction())
    #forceref $oXML_COM_ErrorHandler

    ; TODO $bUTF8 = False -- change to $iEncoding = $FO_UTF8_NOBOM
    If Not ($sXML_FileFullPath <> "" Or IsString($sXML_FileFullPath)) Then
        Return SetError($XMLWRAPPER_ERROR_PARAMETER, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE)
    ElseIf FileExists($sXML_FileFullPath) Then
        Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_GENERAL, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    Local $oXmlDoc = _XML_CreateDOMDocument($iDOM_Version)
    If @error Then Return SetError(@error, @extended, $XMLWRAPPER_RESULT_FAILURE)

    Local $oProcessingInstruction = $oXmlDoc.createProcessingInstruction('xml', 'version="1.0"' & (($bUTF8) ? 'encoding="UTF-8"' : ''))
    If $oXmlDoc.parseError.errorCode Then
        Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    $oXmlDoc.appendChild($oProcessingInstruction)
    If @error Then Return SetError($XMLWRAPPER_ERROR_NODEAPPEND, $NODE_PROCESSING_INSTRUCTION, $XMLWRAPPER_RESULT_FAILURE)

    Local $oXML_RootElement = $oXmlDoc.createElement($sRoot)
    $oXmlDoc.documentElement = $oXML_RootElement

    ; TODO use _XML_SaveToFile
    $oXmlDoc.save($sXML_FileFullPath)
    If @error Then Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE)

    If $oXmlDoc.parseError.errorCode Then
        Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    Return SetError($XMLWRAPPER_ERROR_OK, $XMLWRAPPER_EXT_DEFAULT, $oXmlDoc)

EndFunc   ;==>_XMLCreateFile

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/21/2015 at 7:11 AM, mLipok said:

here is fix.

Func _XMLCreateFile($sXML_FileFullPath, $sRoot, $bUTF8 = False, $iDOM_Version = Default)
    ; Error handler, automatic cleanup at end of function
    Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_UserFunction())
    #forceref $oXML_COM_ErrorHandler

    ; TODO $bUTF8 = False -- change to $iEncoding = $FO_UTF8_NOBOM
    If Not ($sXML_FileFullPath <> "" Or IsString($sXML_FileFullPath)) Then
        Return SetError($XMLWRAPPER_ERROR_PARAMETER, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE)
    ElseIf FileExists($sXML_FileFullPath) Then
        Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_GENERAL, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    Local $oXmlDoc = _XML_CreateDOMDocument($iDOM_Version)
    If @error Then Return SetError(@error, @extended, $XMLWRAPPER_RESULT_FAILURE)

    Local $oProcessingInstruction = $oXmlDoc.createProcessingInstruction('xml', 'version="1.0"' & (($bUTF8) ? 'encoding="UTF-8"' : ''))
    If $oXmlDoc.parseError.errorCode Then
        Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    $oXmlDoc.appendChild($oProcessingInstruction)
    If @error Then Return SetError($XMLWRAPPER_ERROR_NODEAPPEND, $NODE_PROCESSING_INSTRUCTION, $XMLWRAPPER_RESULT_FAILURE)

    Local $oXML_RootElement = $oXmlDoc.createElement($sRoot)
    $oXmlDoc.documentElement = $oXML_RootElement

    ; TODO use _XML_SaveToFile
    $oXmlDoc.save($sXML_FileFullPath)
    If @error Then Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE)

    If $oXmlDoc.parseError.errorCode Then
        Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE)
    EndIf

    Return SetError($XMLWRAPPER_ERROR_OK, $XMLWRAPPER_EXT_DEFAULT, $oXmlDoc)

EndFunc   ;==>_XMLCreateFile

 

it's still not working :(

Posted (edited)

so you should Wait I publish today a new version

...minimum 10 hour.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/21/2015 at 7:59 AM, mLipok said:

so you should Wait I publish today a new version

...minimum 10 hour.

OK ! Thank you very much !

 

Ah , If can, you 'll combine ADO_CONSTANTS.au3 to XMLWrapperEx.au3 !

Posted

new version:

  Quote

    2015/10/22
    "1.1.1.08"
    . ADDED: Description for _XML_ErrorParser_GetDescription() - mLipok
    . ADDED: Description for _XML_Array_GetNodesProperties() - mLipok
    . Fixed: Function: _XMLCreateFile () - mLipok
    .        Isue with usage of Tenary Operator in $oXmlDoc.createProcessingInstruction("xml", 'version="1.0"' & (($bUTF8) ? ' encoding="UTF-8"' : ''))
    . Renamed: Function: _XMLCreateFile >> _XML_CreateFile - mLipok
    . Completed: Function: _XML_CreateFile - mLipok
    . !!! EXAMPLES FILE: New Example: Example_9__XML_CreateFile() - mLipok
    . !!! EXAMPLES FILE: Changed to Keep the changed Script Breaking Changes - mLipok
    . Renamed: Function: __XML_ComErrorHandler_UserFunction >> _XML_ComErrorHandler_UserFunction : is now normal function - not internal - mLipok
    . NEW: methode of transfer UDF internal COM Error Handler to the user function - mLipok
    .        just use _XML_ComErrorHandler_UserFunction() like in example
    .
    SCRIPT BREAKING CHANGES
    . Renamed: Enums: $XMLWRAPPER_RESULT_ >> $XML_RET_ - mLipok
    . Renamed: Enums: $XMLWRAPPER_EXT_ >> $XML_EXT_ - mLipok
    . Renamed: Enums: $XMLWRAPPER_ERROR_ >> $XML_ERR_ - mLipok
    . Renamed: Enums: $NODE_ >> $XML_NODE_ - mLipok
    . Removed: Parameter: _XML_CreateDOMDocument > $vComErrFunc - mLipok

Download link. 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/21/2015 at 8:03 AM, scila1996 said:

OK ! Thank you very much !

Check new version.

Example_9__XML_CreateFile()

 

  On 10/21/2015 at 8:03 AM, scila1996 said:

Ah , If can, you 'll combine ADO_CONSTANTS.au3 to XMLWrapperEx.au3 !

No.
ADO_CONSTANTS.au3 is separate file as it is also part of other "WorkInProgess" UDF (long term project).

mLipok

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Yeah, it's working and i'am still testing . But i have a problem with the content of XML File

<?xml version="1.0" encoding="UTF-8"?>
<SETTINGS><MyNewNode First="1" Second="2">SomeText</MyNewNode></SETTINGS>

File is created

How to like this ?

 

<?xml version="1.0" encoding="UTF-8"?>
<SETTINGS>
    <MyNewNode First="1" Second="2">SomeText</MyNewNode>
</SETTINGS>

 

Posted

use _XML_TIDY() before save.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/22/2015 at 3:31 AM, scila1996 said:

You are check few functions is not working .

- XMLCreateChildNode

- XMLCreateChildNodeWAttr

Please try to learn how to correctly post bug reports.
I mean if you say not working then you should post small example.

or at list the single line of code wich show how you use it 

and always return and @error and @extended  values

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I'am sorry . Because at that time, i'am styding at University School. The Result test script and @error code !I'am sorry . Because at that time, i'am styding at University . The Result test script and @error code !

#include "XMLWrapperEx.au3"

Local $oXMLDoc = _XML_CreateFile("settings.xml", "Settings", True)
Local $aAttr = ["type", "name"]
Local $aVal = ["Menu", "Test"]
MsgBox(64, "", (_XMLCreateChildNodeWAttr($oXMLDoc, "Settings", "Node0", $aAttr, $aVal) ? "true" : "false") & @CRLF & "@Error Code : " & @error) ; This Command Line is return "false : @error 4"
_XML_Load($oXMLDoc, _XML_TIDY($oXMLDoc))
_XML_SaveToFile($oXMLDoc, "settings.xml")

@Error Code : 4

Edited by scila1996
Posted

minimum 12 hours waitng.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

You are check for _XML_GetNodeAttributeValue . It's not working and return 0 @error code 7

XML File

<?xml version="1.0" encoding="Windows-1258" standalone="no"?><Settings>
    <node0 type="menu0"/>
</Settings>

This code !

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
MsgBox(64, "", _XML_NodeExists($oXMLDoc, "Settings/node0")) ; Return 1 ok
Local $onode = _XML_SelectNodes($oXMLDoc, "Settings/node0")
MsgBox(64, "", _XML_GetNodeAttributeValue($onode, "type") & @CRLF & "@Error Code :" & @error) ; return 0 | @error code = 7

 

I think you so modify the _XML_GetNodeAttributeValue into :)

Func _XML_GetNodeAttributeValue(ByRef $oXmlDoc, $sAttribute_Name)

 

Edited by scila1996
Posted (edited)

This function also not working

 

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
Local $aAttr[0], $aVal[0]
MsgBox(64, "", _XMLGetAllAttrib($oXMLDoc, "Settings/Node0", $aAttr, $aVal) & @CRLF & "@Error Code " & @error) ; return 0 | @Error code = 22

XML File

<?xml version="1.0" encoding="Windows-1258" standalone="no"?><Settings>
    <node0 type="menu0" icon="shell32.dll" index="5"/>
</Settings>

 

Edited by scila1996
Posted (edited)

Have a problem with _XML_DeleteNode

If delete one or more time it's to leave a "space line" at node just delete . Example :

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Settings>
<node1/>
<node2/>
<node3/>
</Settings>

After delete "node1" and "node2" 

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Settings>


<node3/>
</Settings>

Thereforce i was used _XML_TIDY to fix , but it's still to leave "space line" at that !

Edited by scila1996
Posted (edited)

Thanks for the report will try to fix this weekend, as yesterday I was just tired, and go to sleep :)

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/23/2015 at 5:17 AM, mLipok said:

Thanks for the report will try to fix this weekend, as yesterday I was just tired, and go to sleep :)

 

Me too, but at that time . I'am waiting for your's script :D . I'll try find the errors and report to dev this script . 

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
×
×
  • Create New...