| View previous topic :: View next topic |
| Author |
Message |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Jan 12, 2004 3:08 pm Post subject: Using UNO's Xml sax parser via the API |
|
|
This example demonstrates several things.
* Using the UCB's SimpleFileAccess to read from a file. (UCB = Universal Content Broker)
* Using OOo's XML sax parser.
* Creating a listener with Basic's CreateUnoListener() function.
If you have never used a Sax type of Xml parser before, then this example may not be for you.
OOo has a Sax Xml parser available via. the Uno api. The following program, in Basic, shows how to use it to parse an Xml document. As the document is parsed, events are fired which print little annoying dialog boxes on the screen. (Be sure to parse a VERY SMALL xml document so that you only have to click OK about a dozen or so times!)
| Code: | Sub Main
cXmlFile = "C:\TestData.xml"
cXmlUrl = ConvertToURL( cXmlFile )
ReadXmlFromUrl( cXmlUrl )
End Sub
' This routine demonstrates how to use the Universal Content Broker's
' SimpleFileAccess to read from a local file.
Sub ReadXmlFromUrl( cUrl )
' The SimpleFileAccess service provides mechanisms to open, read, write files,
' as well as scan the directories of folders to see what they contain.
' The advantage of this over Basic's ugly file manipulation is that this
' technique works the same way in any programming language.
' Furthermore, the program could be running on one machine, while the SimpleFileAccess
' accesses files from the point of view of the machine running OOo, not the machine
' where, say a remote Java or Python program is running.
oSimpleFileAccess = createUnoService( "com.sun.star.ucb.SimpleFileAccess" )
' Open input file.
oInputStream = oSimpleFileAccess.openFileRead( cUrl )
ReadXmlFromInputStream( oInputStream )
oInputStream.closeInput()
End Sub
Sub ReadXmlFromInputStream( oInputStream )
' Create a Sax Xml parser.
oSaxParser = createUnoService( "com.sun.star.xml.sax.Parser" )
' Create a document event handler object.
' As methods of this object are called, Basic arranges
' for global routines (see below) to be called.
oDocEventsHandler = CreateDocumentHandler()
' Plug our event handler into the parser.
' As the parser reads an Xml document, it calls methods
' of the object, and hence global subroutines below
' to notify them of what it is seeing within the Xml document.
oSaxParser.setDocumentHandler( oDocEventsHandler )
' Create an InputSource structure.
oInputSource = createUnoStruct( "com.sun.star.xml.sax.InputSource" )
With oInputSource
.aInputStream = oInputStream ' plug in the input stream
End With
' Now parse the document.
' This reads in the entire document.
' Methods of the oDocEventsHandler object are called as
' the document is scanned.
oSaxParser.parseStream( oInputSource )
End Sub
'==================================================
' Xml Sax document handler.
'==================================================
' Global variables used by our document handler.
'
' Once the Sax parser has given us a document locator,
' the glLocatorSet variable is set to True,
' and the goLocator contains the locator object.
'
' The methods of the locator object has cool methods
' which can tell you where within the current Xml document
' being parsed that the current Sax event occured.
' The locator object implements com.sun.star.xml.sax.XLocator.
'
Private goLocator As Object
Private glLocatorSet As Boolean
' This creates an object which implements the interface
' com.sun.star.xml.sax.XDocumentHandler.
' The doucment handler is returned as the function result.
Function CreateDocumentHandler()
' Use the CreateUnoListener function of Basic.
' Basic creates and returns an object that implements a particular interface.
' When methods of that object are called,
' Basic will call global Basic functions whose names are the same
' as the methods, but prefixed with a certian prefix.
oDocHandler = CreateUnoListener( "DocHandler_", "com.sun.star.xml.sax.XDocumentHandler" )
glLocatorSet = False
CreateDocumentHandler() = oDocHandler
End Function
'==================================================
' Methods of our document handler call these
' global functions.
' These methods look strangely similar to
' a SAX event handler. ;-)
' These global routines are called by the Sax parser
' as it reads in an XML document.
' These subroutines must be named with a prefix that is
' followed by the event name of the com.sun.star.xml.sax.XDocumentHandler interface.
'==================================================
Sub DocHandler_startDocument()
Print "Start document"
End Sub
Sub DocHandler_endDocument()
' Print "End document"
End Sub
Sub DocHandler_startElement( cName As String, oAttributes As com.sun.star.xml.sax.XAttributeList )
Print "Start element", cName
End Sub
Sub DocHandler_endElement( cName As String )
' Print "End element", cName
End Sub
Sub DocHandler_characters( cChars As String )
End Sub
Sub DocHandler_ignorableWhitespace( cWhitespace As String )
End Sub
Sub DocHandler_processingInstruction( cTarget As String, cData As String )
End Sub
Sub DocHandler_setDocumentLocator( oLocator As com.sun.star.xml.sax.XLocator )
' Save the locator object in a global variable.
' The locator object has valuable methods that we can
' call to determine
goLocator = oLocator
glLocatorSet = True
End Sub
|
You need some XML to parse, so create a document named C:\TestData.xml, and put the following text into it.
| Code: | <Employees>
<Employee id="101">
<Name>
<First>John</First>
<Last>Smith</Last>
</Name>
<Address>
<Street>123 Main</Street>
<City>Lawrence</City>
<State>KS</State>
<Zip>66049</Zip>
</Address>
<Phone type="Home">785-555-1234</Phone>
</Employee>
<Employee id="102">
<Name>
<First>Bob</First>
<Last>Jones</Last>
</Name>
<Address>
<Street>456 Puke Drive</Street>
<City>Lawrence</City>
<State>KS</State>
<Zip>66049</Zip>
</Address>
<Phone type="Home">785-555-1235</Phone>
</Employee>
</Employees>
|
If nobody would mind, I might try to post a better example later when I have more time, such as how to turn the above Xml into, say, a spreadsheet.
I hope this example is useful to someone. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Azaroth Guest
|
Posted: Wed Jan 21, 2004 12:06 pm Post subject: |
|
|
Wonderful post.
I've translated it into Python (my preferred language) but I'm stuck on how to do the transformation from a string rather than a stream. This is particularly useful for Python as neither 4Suite nor PyXML will work with the OOo python interpreter (as far as I know -- they die with a unicode length exception for me at least, UCS4 vs UCS2)
As far as I can tell from the API documentation, I would need to implement an XInputStream class that acted like the StringIO class in the std python lib? Is there an easier way than this?
Many thanks for your python snippets to date, in both forums
--Azaroth |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Wed Jan 21, 2004 12:52 pm Post subject: |
|
|
In order to parse from some other data source, such as large string in memory, you would need to write a Service which implements the XInputStream interface. (I don't know of such a service already in OOo.)
It is possible to write services in Python. Or Java. In either case, a service needs to be added to OOo's registry. (Not to be confused with Windows' registry.) You would probably need to use pkgchk to install it. Although from time to time I continue my investigation into how to register a service via. a Basic macro. If this could be done, a Basic macro could create your python source files on the user's disk, and then register them in a way that is very easy for an end user to accomplish.
A number of times I've thought that some new services need to be written that would put more power into the hands of Basic programmers. For instance, some simple Collections type services so that Basic programmers could create, say a HashMap, and then add things to it. Another example would be a DOM type XML parser written in Java, and installed as a Service so that it can be instantiated from either Basic or Python. You cold then read in an XML, do transforms on it, manipulate the DOM structure, and then re-write it back out as text.
I'm glad you liked the message. I wasn't sure if it would be useful to anyone when I wrote it. I was excited about the technique, to parse Xml from OOo Basic, so I posted it. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Azaroth Guest
|
Posted: Wed Jan 21, 2004 3:23 pm Post subject: |
|
|
Thanks for the clarification about what's required for the InputStream. Are there good examples of this, in particular via Python? (I'll go looking now, but if you have one handy...)
On the DOM parser front, what I'm looking at implementing in the first instance is a SAX to DOM DocumentHandler using the XmlDomGenerator Handler from minidom. The reason I need to use strings is that the documents will be fetched via an IR protocol (Z39.50 and/or SRW) rather than read from disk. (Eg the bibliographic project)
Thanks again,
--Azaroth |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
Azaroth Guest
|
Posted: Fri Jan 23, 2004 11:47 am Post subject: Python DOM code |
|
|
Here is my code for a SAX to DOM handler in Python.
It needs the Addons.xcu from the hello_world sample in the PyUno bridge.
There's a lot of debugging stuff left in there, and the exception handling is close to painful, but in the spirit of 'release early, release often', here's the basics.
(It also demonstrates everything I can find out of Python examples)
Thanks to DannyB for the assistance.
This should be treated as GPL.
--Azaroth
| Code: |
import uno, unohelper, traceback, sys
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
import urllib
from com.sun.star.io import XInputStream
from com.sun.star.xml.sax import XDocumentHandler
from xml.dom.minidom import Document
class StringInputStream(unohelper.Base, XInputStream):
""" Minimal Implementation of XInputStream """
def __init__(self, txt, top):
self.top = top
self.data = txt
self.position = 0
def readBytes(self, foo, n):
start = self.position
self.position += (n+1)
foo = self.data[start:self.position]
return (len(foo), uno.ByteSequence(foo))
def readSomeBytes(self, foo, n):
return self.readBytes(foo, n)
def skipBytes(self, n):
self.position += n;
def available(self):
return len(self.data) - self.position;
def closeInput(self):
self.data = None
class DomDocHandler(unohelper.Base, XDocumentHandler):
""" Minimal implementation of XDocumentHandler """
nodeStack = []
document = None
currText = ""
locator = None
top = None
def __init__(self, top):
self.top = top
self.cursor = self.top.text.createTextCursor()
self.nodeStack = []
self.document = Document()
def startDocument(self):
pass
def endDocument(self):
pass
def startElement(self, name, attribs):
try:
elem = self.document.createElement(name)
# attribs is: XAttributeList
l = attribs.getLength()
if (l > 0):
for idx in range(attribs.getLength()):
n = attribs.getNameByIndex(idx)
v = attribs.getValueByIndex(idx)
elem.setAttribute(n, v)
if (self.nodeStack):
self.nodeStack[-1].appendChild(elem)
else:
self.document.documentElement = elem
self.nodeStack.append(elem)
except:
txt = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
txt = '\n'.join(txt)
self.top.text.insertString(self.cursor, txt, 0)
def endElement(self, name):
self.nodeStack.pop()
def characters(self, text):
if (text.isspace()):
text = " "
d = self.document.createTextNode(text)
if (self.nodeStack):
self.nodeStack[-1].appendChild(d)
def setDocumentLocator(self, loc):
self.locator = loc
def ignorableWhitespace(self, space):
pass
def processingInstruction(self, aTarget, aData):
pass
class TestActionListener(XActionListener, unohelper.Base):
""" Implementation of XActionListener to do Z searches """
text = None
def __init__(self, top, edit):
self.top = top
self.query = edit
self.text = top.text
def disposing(self):
# What does this do??
pass
def actionPerformed(self, event):
cursor = self.text.createTextCursor()
try:
# Get some XML from somewhere...
fh = urllib.urlopen('http://srw.cheshire3.org:8080/l5r')
xml = fh.read()
parser = self.top.createService("com.sun.star.xml.sax.Parser")
handler = DomDocHandler(self.top)
parser.setDocumentHandler(handler)
stream = StringInputStream(xml, self.top)
inputSrc = self.top.createStruct("com.sun.star.xml.sax.InputSource")
inputSrc.aInputStream = stream
parser.parseStream(inputSrc)
doc = handler.document
elem = doc.documentElement
# Now we have some DOM. Woot.
# Do with it as we want. :)
except Exception, err:
txt = traceback.format_exception(sys.exc_type, sys.exc_value,
sys.exc_traceback)
txt = '\n'.join(txt)
self.text.insertString(cursor, txt, 0)
def createDialog(top):
buttonName = "button1"
textName = "text1"
labelName = "label1"
dialogModel = top.createService("com.sun.star.awt.UnoControlDialogModel")
dialogModel.PositionX = 100
dialogModel.PositionY = 100
dialogModel.Width = 150
dialogModel.Height = 100
dialogModel.Title = "Z3950 Search Dialog"
buttonModel = dialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
buttonModel.PositionX = 115
buttonModel.PositionY = 10
buttonModel.Width = 20
buttonModel.Height = 10
buttonModel.Name = buttonName
buttonModel.TabIndex = 0
buttonModel.Label = "Search"
textModel = dialogModel.createInstance("com.sun.star.awt.UnoControlEditModel")
textModel.PositionX = 10
textModel.PositionY = 10
textModel.Height = 10
textModel.Width = 100
textModel.Name = textName
labelModel = dialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
labelModel.PositionX = 10
labelModel.PositionY = 0
labelModel.Width = 30
labelModel.Height = 10
labelModel.Name = labelName
labelModel.Label = "A Text Box:"
dialogModel.insertByName(buttonName, buttonModel)
dialogModel.insertByName(textName, textModel)
dialogModel.insertByName(labelName, labelModel)
dialog = top.createService("com.sun.star.awt.UnoControlDialog")
dialog.setModel(dialogModel)
listener = TestActionListener(top, textModel)
buttonCtrl = dialog.getControl(buttonName)
buttonCtrl.addActionListener(listener)
dialog.createPeer(top.createService("com.sun.star.awt.Toolkit"), None)
dialog.execute()
dialog.dispose()
class HelloWorld(unohelper.Base, XJobExecutor):
ctx = None
text = None
coreReflection = None
def __init__(self, ctx):
# Context
self.ctx = ctx
def trigger(self, args):
desktop = self.createService("com.sun.star.frame.Desktop")
model = desktop.getCurrentComponent()
text = model.Text
self.text = text
try:
createDialog(self)
except Exception, err:
cursor = self.text.createTextCursor()
txt = traceback.format_exception(sys.exc_type, sys.exc_value,
sys.exc_traceback)
txt = '\n'.join(txt)
self.text.insertString(cursor, txt, 0)
def createService(self, cClass):
return self.ctx.ServiceManager.createInstanceWithContext(cClass, self.ctx)
def getCoreReflection(self):
if not self.coreReflection:
self.coreReflection = self.createService(
"com.sun.star.reflection.CoreReflection")
return self.coreReflection
def createStruct(self, cTypeName):
"""Create a UNO struct and return it.
"""
oCoreReflection = self.getCoreReflection()
oXIdlClass = oCoreReflection.forName( cTypeName )
oReturnValue, oStruct = oXIdlClass.createObject( None )
return oStruct
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
HelloWorld,
"org.openoffice.comp.pyuno.demo.HelloWorld",
("com.sun.star.task.Job",),)
|
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
goa103 OOo Advocate


Joined: 11 May 2003 Posts: 279
|
Posted: Mon Mar 21, 2005 12:56 am Post subject: Re: Using UNO's Xml sax parser via the API |
|
|
Very interesting topic. I'm into XML these days .
| DannyB wrote: | [code] ' Create an InputSource structure.
oInputSource = createUnoStruct( "com.sun.star.xml.sax.InputSource" )
With oInputSource
.aInputStream = oInputStream ' plug in the input stream
End With |
I don't really understand the above lines. Is aInputStream an attribute ? I never used the With statement but it sounds like it kind of copy one object into an other... I don't really understand why we can't just assign one to an other... _________________ An OOo mascot designer |
|
| Back to top |
|
 |
goa103 OOo Advocate


Joined: 11 May 2003 Posts: 279
|
Posted: Mon Mar 21, 2005 1:00 am Post subject: |
|
|
| DannyB wrote: | | A number of times I've thought that some new services need to be written that would put more power into the hands of Basic programmers. For instance, some simple Collections type services so that Basic programmers could create, say a HashMap, and then add things to it. Another example would be a DOM type XML parser written in Java, and installed as a Service so that it can be instantiated from either Basic or Python. You cold then read in an XML, do transforms on it, manipulate the DOM structure, and then re-write it back out as text. |
I'm new to OOo development and only develop small macros for the moment, but I know Java. I wonder why most of the coding snippets are in Basic if the language is that limited. Is developing Java macro so hard ? All references on the subject are welcome, I would like to develop Java macro in the future, I'm not really into Basic.
| DannyB wrote: | | I'm glad you liked the message. I wasn't sure if it would be useful to anyone when I wrote it. I was excited about the technique, to parse Xml from OOo Basic, so I posted it. |
Same feeling here, working with XML files is very entertaining and interesting. For example I thought about developing a macro to feed my documents from XML documents. In our case I would display a Employees table in a writer document. My current problem is to use a User text fields or embed-inline a macro in a writer document... I guess the solution would be to use some kind of macro text field. Just some thoughts . _________________ An OOo mascot designer |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Mar 21, 2005 10:15 am Post subject: Re: Using UNO's Xml sax parser via the API |
|
|
| goa103 wrote: |
| DannyB wrote: | [code] ' Create an InputSource structure.
oInputSource = createUnoStruct( "com.sun.star.xml.sax.InputSource" )
With oInputSource
.aInputStream = oInputStream ' plug in the input stream
End With |
I don't really understand the above lines. Is aInputStream an attribute ? I never used the With statement but it sounds like it kind of copy one object into an other... I don't really understand why we can't just assign one to an other... |
Yes, aInputStream is a member of oInputSource. Instead of the WITH, I would have just written something like
oInputSource.aInputStream = oInputStream ' plug in the input stream _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Mar 21, 2005 10:23 am Post subject: |
|
|
| goa103 wrote: | | I'm new to OOo development and only develop small macros for the moment, but I know Java. I wonder why most of the coding snippets are in Basic if the language is that limited. |
Several reasons.
OOo Macros are easy to distribute. They can be distributed within documents. In the past, this has not been possible with Java, or any other language.
Now with OOo 2, you can write macros in other languages (Python, BeanShell, JavaScript) and distribute within an office document that anyone else can just open and click your document's buttons.
| goa103 wrote: | | Is developing Java macro so hard ? |
Yes. Very much more difficult. Lots of queryInterface() business that you don't need to do in Python, Basic, or JavaScript. (I'm not sure about BeanShell, which is interpreted Java.)
In OOo 2.0 interfaces can now multiple-inherit from several superinterfaces. With some changes to the IDL files of the API, developing in Java should become much easier in the future.
Not only has Java been very much more difficult to use to program OOo's API, but there is the previously mentioned issue of how you even deploy your code. You can't just put it into a document as a macro.
You could write an external program that runs outside of OOo. (See my Maze Generator on OOoMacros.org) But then the end user must configure OOo to listen for an uno connection. Or more recently, you can use one of the Bootstrap classes techniques that will launch the OOo for you and connect to it over a named pipe, if you want to run the Java program and the OOo on the same computer.
Or you could package your Java code as an UNO component. This is also a fairly high barrier to jump over if you are a new developer.
| goa103 wrote: | | All references on the subject are welcome, I would like to develop Java macro in the future, I'm not really into Basic. |
Use OOo 2 beta, and play with BeanShell. This is probably the easiest approach to get started.
Really, I should take this discussion to a seperate thread. But there have been some past discussions of Java programming.
Danny's Notes about programming OOo in Java
http://www.oooforum.org/forum/viewtopic.php?p=31278#31278
http://www.oooforum.org/forum/viewtopic.php?p=29989#29989
Java vs. Python for OOo
http://www.oooforum.org/forum/viewtopic.php?p=29457#29457
In Java, how to use API Docs to find available interfaces, methods.
How to call getSupportedServiceNames()
http://www.oooforum.org/forum/viewtopic.php?p=58512#58512
Brief explanation of one aspect of the API
http://www.oooforum.org/forum/viewtopic.php?p=31873#31873
Java trips and ticks
http://www.oooforum.org/forum/viewtopic.php?p=36119#36119
http://www.oooforum.org/forum/viewtopic.php?t=4791
http://www.oooforum.org/forum/viewtopic.php?t=860
http://www.oooforum.org/forum/viewtopic.php?t=4071
http://www.oooforum.org/forum/viewtopic.php?p=17405#17405
http://www.oooforum.org/forum/viewtopic.php?t=4520
http://www.oooforum.org/forum/viewtopic.php?t=4000
http://www.oooforum.org/forum/viewtopic.php?t=4094
http://www.oooforum.org/forum/viewtopic.php?t=3763
http://www.oooforum.org/forum/viewtopic.php?t=765
http://www.oooforum.org/forum/viewtopic.php?t=1480
http://www.oooforum.org/forum/viewtopic.php?t=2322
http://www.oooforum.org/forum/viewtopic.php?t=5513
Load a document from an XInputStream
http://www.oooforum.org/forum/viewtopic.php?t=6807
Document output to Http Response
http://www.oooforum.org/forum/viewtopic.php?p=58945#58945
http://www.oooforum.org/forum/viewtopic.php?p=55665#55665 _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
goa103 OOo Advocate


Joined: 11 May 2003 Posts: 279
|
Posted: Tue Mar 22, 2005 1:46 am Post subject: Re: Using UNO's Xml sax parser via the API |
|
|
| DannyB wrote: | Instead of the WITH, I would have just written something like
oInputSource.aInputStream = oInputStream ' plug in the input stream |
Hum... I don't get it. So what's the difference between WITH and without WITH ? _________________ An OOo mascot designer |
|
| Back to top |
|
 |
goa103 OOo Advocate


Joined: 11 May 2003 Posts: 279
|
Posted: Tue Mar 22, 2005 2:09 am Post subject: |
|
|
| DannyB wrote: | | OOo Macros are easy to distribute. They can be distributed within documents. In the past, this has not been possible with Java, or any other language. |
Actually I and some OOo users I know think that sharing macros is not that easy. The only solution I found was to develop my macros in a library and deploy it by patching existing OOo installation. But I'm sure there's an easy way to export and import a library... However I don't have to deploy the library so often. And let's say that only 2-3 people are interested by the few buggy macros I developed .
| DannyB wrote: | | Now with OOo 2, you can write macros in other languages (Python, BeanShell, JavaScript) and distribute within an office document that anyone else can just open and click your document's buttons. |
Hum... I don't like using a document to use a macro I prefer to add a button to the interface, that's why I chose the library-way.
I think the ideal scripting language for me would be PHP5. You would get the best of both worlds : simple & object oriented. But I should definitely learn Python because it seems very powerful and simple. Java-BeanShell sounds interesting too. JavaScript is to functional, too Basic.
| DannyB wrote: | | In OOo 2.0 interfaces can now multiple-inherit from several superinterfaces. With some changes to the IDL files of the API, developing in Java should become much easier in the future. |
There are the pros & cons of Java and COM-based technologies I guess. But most Java IDEs have a powerful auto completion feature so creating COM objects instances and accessing their methods is not that hard. But I agree that Basic makes the development process far much easier. After all once you're into OOo you want to use its objects as local objects, nor specifying namespaces and other COM weirdlingz .
| DannyB wrote: | | Really, I should take this discussion to a seperate thread. But there have been some past discussions of Java programming. |
We definitely need a FAQ forum . FAQ about OOo and Java, OOo and Python... Thanks you so much for all there references ! Topics referencing and classification is so hard with phpBB ! Any idea how we could improve the forum ? As I mentionned in an other topic I'm working on a simple MOD for phpBB to add some BBCode tags to reference topics, posts... And using special topics (meta-topics) to categorize other topics would definitely be helpful. One topic to rule them all . _________________ An OOo mascot designer |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Mar 25, 2005 9:33 am Post subject: Re: Using UNO's Xml sax parser via the API |
|
|
| goa103 wrote: | | Hum... I don't get it. So what's the difference between WITH and without WITH ? |
In Basic, I believe that WITH is just syntax sugar. It (probably) has no runtime advantage.
In real compiled languages, a construct like WITH is actually a source level way to say "dereference this pointer, and hold it in a register" for optimization. Then within the WITH you use a dot-identifier notation to easily access offsets from that pointer.
For example, in Pascal, using WITH, but using it carefully, may actually get you some runtime performance benefit.
OTOH, using WITH to enclose a two-page block of code may lose any performance advantage.
I could go on about how modern sophisticated compilers, vs. 1980's compilers, probably don't make any difference in whether you write a WITH or not. Three seperate lines like....
oMyPointer.abc = 37
oMyPointer.def = 49
oMyPointer.xyz = 38
probably optimizes to only computing the pointer once anyway on a modern compiler.
In the old days, you might see a Pascal construct like....
WITH oMyPointer^.foo[xy].jbc^.bar^ DO BEGIN
END
where you did a pointer dereference, index, array subscript, index, pointer dereference, index, and another pointer dereference. The WITH would only do this once. Then the embedded dot-references would all share the same computation of the pointer. Does that make sense?
I Basic, I think it is all just syntax sugar. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Mar 25, 2005 9:36 am Post subject: |
|
|
| goa103 wrote: | We definitely need a FAQ forum . FAQ about OOo and Java, OOo and Python... Thanks you so much for all there references ! Topics referencing and classification is so hard with phpBB ! Any idea how we could improve the forum ? As I mentionned in an other topic I'm working on a simple MOD for phpBB to add some BBCode tags to reference topics, posts... And using special topics (meta-topics) to categorize other topics would definitely be helpful. One topic to rule them all . |
I wish that there were some way to organize the vast amount of information here at OOoForum. But then this is a topic to take up on the Site Feedback section.
The best thing that I have found is to keep track of past subjects that you personally find interesting. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|