Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
52
Task/XML-Output/FutureBasic/xml-output.basic
Normal file
52
Task/XML-Output/FutureBasic/xml-output.basic
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
include "NSLog.incl"
|
||||
include "Tlbx XML.incl"
|
||||
|
||||
local fn FormattedXMLTest
|
||||
// Input data
|
||||
CFArrayRef names = @[@"April", @"Tam O'Shanter", @"Emily"]
|
||||
CFArrayRef remarks = @[@"Bubbly: I'm > Tam and <= Emily",
|
||||
@"Burns: \"When chapman billies leave the street ...\"",
|
||||
@"Short & shrift"]
|
||||
|
||||
// Root element
|
||||
XMLElementRef root = fn XMLElementWithName( @"CharacterRemarks" )
|
||||
|
||||
// Create each <Character> element
|
||||
for NSInteger i = 0 to fn ArrayCount(names) - 1
|
||||
XMLElementRef character = fn XMLElementWithName( @"Character" )
|
||||
|
||||
// Add name attribute
|
||||
XMLNodeRef nameAttr = fn XMLNodeAttributeWithName( @"name", names[i] )
|
||||
XMLElementAddAttribute( character, nameAttr )
|
||||
|
||||
// Add remark as text content
|
||||
XMLNodeRef textNode = fn XMLNodeTextWithStringValue( remarks[i] )
|
||||
XMLElementAddChild( character, textNode )
|
||||
XMLElementAddChild( root, character )
|
||||
next
|
||||
|
||||
// Build the document
|
||||
XMLDocumentRef doc = fn XMLDocumentWithRootElement(root)
|
||||
XMLDocumentSetCharacterEncoding( doc, @"UTF-8" )
|
||||
XMLDocumentSetVersion( doc, @"1.0" )
|
||||
|
||||
// Output file path
|
||||
CFStringRef path = @"/tmp/characters.xml"
|
||||
|
||||
// Write the XML to file (pretty printed)
|
||||
CFDataRef xmlData = fn XMLDocumentXMLDataWithOptions( doc, NSXMLNodePrettyPrint )
|
||||
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
|
||||
CFURLRef url = fn URLByAppendingPathComponent( desktopURL, @"XML_Test.xml" )
|
||||
BOOL success = fn DataWriteToURL( xmlData, url, NSDataWritingAtomic, NULL )
|
||||
|
||||
if ( success == YES )
|
||||
NSLog( @"XML file successfully written to: %@", url )
|
||||
fn WorkSpaceOpenURL( url )
|
||||
else
|
||||
NSLog( @"Failed to write XML file" )
|
||||
end if
|
||||
end fn
|
||||
|
||||
fn FormattedXMLTest
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue