Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
AddAttribute - Insert New Attribute in XML NodeDemonstrates adding an name=value attribute to an XML tag.
This example uses the XML sample file sample1.xml. The sample1.xml file contains this content: LOCAL loXml LOCAL lnSuccess LOCAL lnBFound LOCAL lnNumChildren LOCAL i loXml = CreateObject('Chilkat.Xml') lnSuccess = loXml.LoadXmlFile("sample1.xml") IF (lnSuccess <> 1) THEN ? loXml.LastErrorText QUIT ENDIF * Navigate to the "books" node: lnBFound = loXml.FindChild2("books") IF (lnBFound = 0) THEN ? "No books child found!" QUIT ENDIF lnNumChildren = loXml.NumChildren FOR i = 0 TO lnNumChildren - 1 * Navigate to the Nth book (we'll assume success...) lnBFound = loXml.GetChild2(i) * Display the book title: ? loXml.GetAttrValue("title") * Add a new integer attribute: * Should never fail.. lnSuccess = loXml.AddAttributeInt("bookId",i) * Add a new unread="yes" attribute: lnSuccess = loXml.AddAttribute("unread","yes") * Navigate back up to the parent: lnSuccess = loXml.GetParent2() NEXT * Navigate back to the document root: loXml.GetRoot2() * Save the updated document: lnSuccess = loXml.SaveXml("modified.xml") IF (lnSuccess <> 1) THEN ? loXml.LastErrorText QUIT ENDIF |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser