Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) AddAttribute - Insert New Attribute in an XML NodeDemonstrates adding an name=value attribute to an XML element.
This example uses the XML sample file here: sample1.xml. The sample1.xml file contains this content:
Use ChilkatAx-win32.pkg Procedure Test Handle hoXml Boolean iSuccess Boolean iBFound Integer iNumChildren Integer i String sTemp1 Get Create (RefClass(cComChilkatXml)) To hoXml If (Not(IsComObjectCreated(hoXml))) Begin Send CreateComObject of hoXml End Get ComLoadXmlFile Of hoXml "qa_data/xml/sample1.xml" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoXml To sTemp1 Showln sTemp1 Procedure_Return End // Navigate to the "books" element: Get ComFindChild2 Of hoXml "books" To iBFound If (iBFound = False) Begin Showln "No books child found!" Procedure_Return End Get ComNumChildren Of hoXml To iNumChildren Move 0 To i While (i < iNumChildren) // Navigate to the Nth book Get ComGetChild2 Of hoXml i To iSuccess // Display the book title: Get ComGetAttrValue Of hoXml "title" To sTemp1 Showln sTemp1 // Add a new integer attribute: // Should never fail.. Get ComAddAttributeInt Of hoXml "bookId" i To iSuccess // Add a new unread="yes" attribute: Get ComAddAttribute Of hoXml "unread" "yes" To iSuccess // Navigate back up to the parent: Get ComGetParent2 Of hoXml To iSuccess Move (i + 1) To i Loop // Navigate back to the document root: Send ComGetRoot2 To hoXml // Save the updated document: Get ComSaveXml Of hoXml "modified.xml" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoXml To sTemp1 Showln sTemp1 Procedure_Return End Get ComGetXml Of hoXml To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.