I am going to make a xslt from data in Calc.
Really I need to replace some data in ready xml files.
I supposed to use a RegEx but sometimes I need to add/delete more siblings.
So XSLT would be a good here.
I played with xslt filters, it works, but not enough for me.
I'd do it from macros.
I think it is possible, but I have not found any template or even comprehensive docs.
I'm new for UNO.
Can you help me to find any appropriate template for BASIC or C++ or any.
Or reference to any docs concerning.
Thank you.
Java and Python have good XML parsing and regular expression libraries. I typically use xml.dom.minidom and re for Python. See here for "Hello World" type macros in these languages.
Basic does not have its own library, although there is an UNO service that provides a SAX style parser. See section 5.38 of Andrew Pitonyak's macro document for an example.
For C++, I typically avoid a lot of string processing or macro writing because it is a lower level language. However there are probably XML parsing libraries available, and macros can be written with some effort.
Related
I'm writing a Program in C++ that is going to use the same input files as an existing Prolog program already uses.
The files will look like these :
expr1(t,[f,g]).
expr1(q,[]).
expr1(r,[e]).
expr2(a).
expr2(b).
expr2(e).
expr2(a,r).
expr2(b,d).
expr2(e,z).
What are some ways of parsing such files? I've read about the Boost Spirit.. anyone got thoughts on this? Or is a way of doing it using the standard C/C++ libraries? Ideas would be great.
Thank you.
That looks like a perfect job for a hand written recursive descent parser. No extra dependencies, easy to write, and straight forward for future maintainers.
What is wrong with Flex and Bison? This does have the benefit of the generated code being independent of libraries which you may or may not have. It is used for things as simple as parsing config files to things like a Javascript parser for Webkit.You might even find a Prolog grammar that you can use.
I would definitely not suggest Boost Spirit unless the task is really a lot more complicated than what it looks lke. There is nothing wrong with Boost Spirit, I mean it is really powerfull and would do the work just fine, but it also requires a lot of learning and might massively increase the compilation time.
Although I agree with Jörgen that a hand written decent parser would be a good option, it doesn't look like you are going to need a context-free parser, so I think a regular expression parser might be enough. If that is the case, I suggest you to take a look at the new regex library introduced in the new C++0x standard.
I'm looking for a simple non-validating XML parser in either C or C++.
Several years back I found one that was just a single file solution but I can't find
it anymore.
I'm after some links and suggested ones that are very small and lightweight
ideally suited for an embedded platform.
Expat
You can work with or without validation and in "streaming mode". It is very lightweight.
What about something like pugixml. From their site...
pugixml is a light-weight C++ XML
processing library. It features:
DOM-like interface with rich traversal/modification capabilities
Extremely fast non-validating XML parser which constructs the DOM
tree from an XML file/buffer
XPath 1.0 implementation for complex data-driven tree queries
Full Unicode support with Unicode interface variants and
automatic encoding conversions
The library is extremely portable and
easy to integrate and use.
pugixml is developed and maintained
since 2006 and has many users. All
code is distributed under the MIT
license, making it completely free to
use in both open-source and
proprietary applications.
Also, this answer has more info.
There is also tinyxml and RapidXml.
There is definitely a pure C, tiny xml parser available. It was cited in an earlier answer on SO, but I can't find it right now. If I remember right, it's just a few hundred lines of code.
Update: Here's the question/answer that references it:
Is there a good tiny XML parser for an embedded C project?
And the actual code:
http://mercurial.intuxication.org/hg/cstuff/file/tip/tinyxml
RapidXML is a single-header (multiple headers if you want extra functionality) ultra-lightweight, ultra-fast implementation. It can operate in "destructive" mode, that means by setting pointers right into the XML and possibly overwriting some, avoiding all extra memory allocations and data copies.
tinyxml is not precisely single-header, but it is still fairly lightweight compared to other parsers. I've used it for half a decade without ever encountering an issue. The author has recently started with "tinyxml-2", which is supposedly better and even more lightweight, but I've not had occasion to actually try that one yet.
http://mercurial.intuxication.org/hg/cstuff/file/tip/tinyxml
can this parser work with nested XML like
<CServiceType>
<serno>61</serno>
<caption1 />
<caption2>Satelite</caption2>
<caption3 />
</CServiceType>
Are you aware of any lexical analyzer or lexer in Qt? I need it for parsing text files.
It is kinda interesting how Qt has evolved into an all-compassing framework that makes the programmer that uses it believe that anything that is useful has to start with the letter Q. Very dot-netty. Qt is just a class library that runs on top of the language, it doesn't preclude using everyday libraries that get a job done. Especially when that's a library that has little to do with presenting a user interface, the job that Qt does so well.
There are many libraries that get lexical analysis and parsing done well. That starts with Lex and Yacc, Flex and Bison next, etcetera. You only have to Qt enable it for error messages, they readily support that.
QXmlReader has allows you to define a lexical handler, for plain text you can use QRegExp. If you want a full blown lexical analyzer take a look at Quex (not Qt specific, but is used to generate a C++ code based on your input).
If you can use it... (it's quite complex if you ask me!) there is the Spirit library from boost.
This can be used "dynamically" in the sense that it does not generate other files that you have to then compile to run your parser.
http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/lex.html
But it's complex (to my point of view) since even just the #include don't always work right (if you include them in the wrong order or the documentation may not match the tutorial, I'm not too sure.) Yet, I see many people using it!
Need to write some C++ code that reads XML string and if i do
something like:
get valueofElement("ACTION_ON_CARD") it returns 3
get valueofElement("ACTION_ON_ENVELOPE") it returns YES
XML String:
<ACTION_ON_CARD>3</ACTION_ON_CARD>
<ACTION_ON_ENVELOPE>YES</ACTION_ON_ENVELOPE>
Any code example would be helpfull
Thanks
writing an xml parser is not necessarily an easy thing to do, so unless it is a requirement you do it yourself I suggest you get a library to do that for you.
There are many available like xerces (pretty complete but not exactly simple), tinyxml (mostly the opposite of xerces, it probably suits best your needs) or libxml (never tried this one)
If you have the schema, you could use codesynthesis xsd compiler.
I recommend the XML parser from the Poco C++ library. It's well documented and easy to use.
I'm trying to create an app to search my company's ColdFusion codebase. I'd like to be able to do intelligent searches, for example: find where a function is defined (and not hit everywhere the function is called). In order to do this, I'd need to parse the ColdFusion code to identify things like function declarations, function calls, database queries, etc.
I've looked into using lex and yacc, but I've never used them before and the learning curve seems very steep. I'm hoping there is something already out there that I could use. My other option is a mess of difficult-to-maintain regex-spaghetti code, which I want to avoid.
I used the source to CFEclipse, since it is open source and has a parser. Not sure about the legality of this if we were selling/redistributing it, but we're only using it for an internal tool.
Writing parsers for real langauges is usually difficult because they contain constructs that Lex and Yacc often don't handle well, e.g., the langauge isn't LALR(1). ColdFusion might be easier than some because of its XML-like style.
If you want to build a sophisticated parser quickly, you might consider using our
DMS Software Reengineering Toolkit which has GLR parsing support.
If you want to avoid writing your own or hacking all those Regexps, you could consider our Source Code Search Engine. It has language-sensitive parsers and can search across very large source code bases very quickly. One of its "language sensitive" parsers is AdhocText, which is designed to handle "generic" programming languages such as those you might find in a random programming book; it even understands XML-like tags such as ColdFusion has. You can download a evaluation version from the link provided to try it.
EDIT 4/3/2010: A recent feature added to the SCSE is the ability to tag definitions and uses separately. That would address the OP's desire to find the function definition rather than all the calls.
None existed. Since ColdFusion is more like scripts than code, I'd imagine it'll be hard to write a parser for it.
ColdFusion Builder can parse CFM/CFC to an outline in Eclipse. Maybe you can do some research on whether a CF Builder plugin can do what you want to do.