Platforms to show: All Mac Windows Linux Cross-Platform
/MacCF/CF XML Parser
Function:
Required plugins for this example: MBS MacCF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/CF XML Parser
This example is the version from Sun, 17th Mar 2012.
Function:
Required plugins for this example: MBS MacCF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/CF XML Parser
This example is the version from Sun, 17th Mar 2012.
Project "CF XML Parser.xojo_binary_project"
Class MainWindow Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
run
End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Sub run()
const kCFXMLParserValidateDocument = 1
const kCFXMLParserSkipMetaData = 2
const kCFXMLParserReplacePhysicalEntities = 4
const kCFXMLParserSkipWhitespace = 8
const kCFXMLParserResolveExternalEntities = 16
const kCFXMLParserAddImpliedAttributes = 32
const kCFXMLParserAllOptions = &h00FFFFFF
const kCFXMLParserNoOptions = 0
dim parser as MyCFXMLParser
parser=new MyCFXMLParser
parser.Create NewCFBinaryDataMBSStr(EditField1.text), nil, kCFXMLParserSkipWhitespace
if parser.parse then
EditField2.Text=output
else
EditField2.text=parser.ErrorDescription.str
end if
End Sub
Property output As string
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class MyCFXMLParser Inherits CFXMLParserMBS
EventHandler Sub AddChild(parent as CFObjectMBS, child as CFObjectMBS)
writeline "---Add Child Called---"
writeline "Parent being added to: "+GetCFString(parent)
writeline "Child being added: "+GetCFString(child)
End EventHandler
EventHandler Function CreateXMLStructure(node as CFXMLNodeMBS) As CFObjectMBS
const kCFXMLNodeTypeDocument = 1
const kCFXMLNodeTypeElement = 2
const kCFXMLNodeTypeAttribute = 3
const kCFXMLNodeTypeProcessingInstruction = 4
const kCFXMLNodeTypeComment = 5
const kCFXMLNodeTypeText = 6
const kCFXMLNodeTypeCDATASection = 7
const kCFXMLNodeTypeDocumentFragment = 8
const kCFXMLNodeTypeEntity = 9
const kCFXMLNodeTypeEntityReference = 10
const kCFXMLNodeTypeDocumentType = 11
const kCFXMLNodeTypeWhitespace = 12
const kCFXMLNodeTypeNotation = 13
const kCFXMLNodeTypeElementTypeDeclaration = 14
const kCFXMLNodeTypeAttributeListDeclaration = 15
dim type as integer
dim TypeStr as string
dim DataStr as string
type=node.TypeCode
Select case type
case kCFXMLNodeTypeDocument
TypeStr="Data Type ID: kCFXMLNodeTypeDocument"
DataStr="Document URL: "+GetNodeDocumentURL(node)
case kCFXMLNodeTypeElement
TypeStr="Data Type ID: kCFXMLNodeTypeElement"
DataStr="Element: "+GetNodeData(node)
case kCFXMLNodeTypeProcessingInstruction
TypeStr="Data Type ID: kCFXMLNodeTypeProcessingInstruction"
DataStr="PI: "+GetNodeData(node)
case kCFXMLNodeTypeComment
TypeStr="Data Type ID: kCFXMLNodeTypeComment "
DataStr="Comment: "+GetNodeData(node)
case kCFXMLNodeTypeText
TypeStr="Data Type ID: kCFXMLNodeTypeText"
DataStr="Text: "+GetNodeData(node)
case kCFXMLNodeTypeCDATASection
TypeStr="Data Type ID: kCFXMLNodeTypeText"
DataStr="CDATA: "+GetNodeData(node)
case kCFXMLNodeTypeEntityReference
TypeStr="Data Type ID: kCFXMLNodeTypeEntityReference"
DataStr="CDATA: "+GetNodeData(node)
case kCFXMLNodeTypeWhitespace
TypeStr="Data Type ID: kCFXMLNodeTypeWhitespace"
DataStr="Whitespace: "+GetNodeData(node)
case kCFXMLNodeTypeEntity
TypeStr="Data Type ID: kCFXMLNodeTypeEntity"
DataStr="Entity: "+GetNodeData(node)
else
TypeStr="Data Type ID: UNKNOWN"
DataStr="Data: "+GetNodeData(node)
end Select
writeline "---Create Structure Called---"
writeline TypeStr
writeline DataStr
// Keep for later Lookup
Return NewCFStringMBS(datastr)
End EventHandler
EventHandler Sub EndXMLStructure(xmlType as CFObjectMBS)
writeline "---End Structure Called for "+GetCFString(xmlType)
End EventHandler
EventHandler Function HandleError(StatusCode as integer) As boolean
writeline "Parse error ("+str(StatusCode)+") "+me.ErrorDescription.Str+" on line "+str(me.LineNumber)+", character "+str(me.Location)+"."
End EventHandler
EventHandler Function ResolveExternalEntity(externalID as CFXMLExternalIDMBS) As CFBinaryDataMBS
writeline "---resolveEntity Called---"
End EventHandler
Function GetNodeData(node as cfxmlnodeMBS) As string
return node.Data.Str
Exception // if it fails, it fails here
End Function
Function GetNodeDocumentURL(node as cfxmlnodembs) As string
dim docinfo as CFXMLDocumentInfoMBS
dim u as CFURLMBS
dim s as CFStringMBS
docinfo=node.GetCFXMLDocumentInfo
u=docinfo.SourceURL
if u<>Nil then
s=u.str
if s<>nil then
return s.Str
end if
end if
Exception // if it fails, it doesn't block the whole event
End Function
Sub writeline(s as string)
MainWindow.output=MainWindow.output+s+chr(13)
End Sub
Property d As dictionary
End Class
Module Util
Function GetCFString(o as cfobjectMBS) As string
dim s as CFStringMBS
if o isa CFStringMBS then // If it's a RB CFString object
s=CFStringMBS(o)
Return s.str
end if
Exception
End Function
End Module
Class App Inherits Application
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCF Plugin.