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
(PowerBuilder) 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:
integer li_rc oleobject loo_Xml integer li_Success integer li_BFound integer li_NumChildren integer i loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") if li_rc < 0 then destroy loo_Xml MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Xml.LoadXmlFile("qa_data/xml/sample1.xml") if li_Success <> 1 then Write-Debug loo_Xml.LastErrorText destroy loo_Xml return end if // Navigate to the "books" element: li_BFound = loo_Xml.FindChild2("books") if li_BFound = 0 then Write-Debug "No books child found!" destroy loo_Xml return end if li_NumChildren = loo_Xml.NumChildren i = 0 do while i < li_NumChildren // Navigate to the Nth book loo_Xml.GetChild2(i) // Display the book title: Write-Debug loo_Xml.GetAttrValue("title") // Add a new integer attribute: // Should never fail.. loo_Xml.AddAttributeInt("bookId",i) // Add a new unread="yes" attribute: loo_Xml.AddAttribute("unread","yes") // Navigate back up to the parent: loo_Xml.GetParent2() i = i + 1 loop // Navigate back to the document root: loo_Xml.GetRoot2() // Save the updated document: li_Success = loo_Xml.SaveXml("modified.xml") if li_Success <> 1 then Write-Debug loo_Xml.LastErrorText destroy loo_Xml return end if Write-Debug loo_Xml.GetXml() destroy loo_Xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.