is there any JOOMLA XML class? - joomla

$hold=$this->load_component_objects();
$hold contain result of my query i made in my table during JOOMLA component development. Now is there any JOOMLA XML library or class that is capable of converting it to XML automatically.

Simple answer is no.
The only XML handling is in JFactory, and it's mainly used by the installer when reading extension manifests.
Basically the installer gets the XML file path retrieves the XML in it's various loadManifestFromXML($xmlfile) methods. These in turn just call JFactory::getXML($xmlfile) which is really just a wrapper on simplexml (PHP manual) and return it as a JXMLElement.
class JXMLElement extends SimpleXMLElement
{
...
}
N.B. you can pass a XML string to getXML() as well as a file path.
More information on your objects structure, would help in determining the best way to get it into an XML format.

Related

Using Page Objects vs Config Files in Selenium

I've been using Ruby Selenium-Webdriver for one of the automation scripts I'm developing and I'm being asked to use Page Objects, we use page objects a lot however for this application I am using CSV file instead, I have defined all the xpaths that I'm using in my application in a CSV file and I'm parsing that CSV file in my script to refer to those objects, I would like to know is there much of a difference in using a class for defining Page Objects or using a CSV file instead apart from performance concern? I believe using a CSV file will be an addon for us from configuration standpoint and will make it much easier to maintain, any suggestions on this?
Edit - In our use case, we're actually automating applications built on a cloud based tool, so basically all the applications share same design structure from HTML standpoint so we define xpath patterns in CSV and then we pass certain parameters to some custom methods that we've developed to generate xpath's automatically using the CSV instead of finding those manually as its overhead for us because we already know that all the applications will share similar xpath pattern for all elements.
Thanks
I think, POM is better than CSV approach. In POM, you put elements for a page in a separate class file. So, if any change is to make then it's easier to find where to change/maintain. Moreover, it won't get too messy as CSV file and you don't need to use extra utility function to parse those.
There is also a pageobjects gem that provides a set of libraries over and above webdriver/watir, simplifying the code.
Plus, why xpaths? Its one of the last recommended ways to identify an element.
As for the frameork aspect, csv should be more of a maintenance problem than PageObjects. Its the basic difference between text and code. You enforce Object oriented approach on your elements in PageObjects but that is not possible with csv.
In the best case scenario, you have created a column/separate sheets defining which page that element xpath belongs to. That sounds like an overhead. As your application / suite grows there can be thousands of elements. Imagine parsing/ manually updating a csv with that kind of data.
Instead in PageObjects, your elements will be restricted to the Page. Any changes to the app will also specify which elements may get impacted. Now, when define your element as an object in PageObject, rather than css, you also dont need to explicitly create your elements by reading the csv.
It completely depends on the application and the type of test you might perform.
Since it is an automated test script, you do not have to really worry about the performance of the script (it might take few more milli seconds to parse, which should be OK).
Maintaining all the elements identification properties & corresponding actions in a CSV file will make the maintenance easier and make the framework application independent which are nice. But maintaining your framework is bit difficult to make it more robust. Both approaches have its own pros and cons.
Refer to below posts [examples are in java - but you will get the idea]:
Keyword driven framework
Advanced Page Objects
Update:
If you like both, you can comeup with your implementation to easily integrate these too.
#ObjectRepository(src="/login.csv")
public class LoginPage{
private Map<String, WebElement> elements;
public void login(){
elements.get("username").sendKeys('');
elements.get("password").sendKeys('');
elements.get("signin").click();
}
}
Ie, define all the elements in a config file like csv/json etc. Let the page object refer to the class for the page elements. All the methods will be part of the page class.

How do I get CsvDozerBeanWriter to pull column headers from Dozer XML mapping files

I'm writing a feature to produce CSV snapshots of screen data.
I need this to be data-driven. Thus I need to avoid hard-coding each snapshot in Java, but rather load it from a data source such as an XML file or a database. The data is contained in Java beans.
I'm using SuperCSV with the Dozer extension both at 2.1.0.
This combination seems perfect since I can code the mappings from the beans to the columns in Dozer XML mapping files.
This works well for the data, but I have not found a way to specify the strings to use for the CSV's column headers other than to hard-code them in Java as is done in all of the examples and test cases I've looked at. That is not data-driven.
Is there a way for me to code the column headers in the mapper file. Or even to extract them from the mapper file, construct a List and pass them to the writerHeader() method?
I think it would be OK to just use the bean property names as the headers, although ideal situation is that I am provided some additional meta-data notation in the XML's <Field> tag that specifies the header.
I'd have posted this on SourceForge, but I'm getting a 500 error there.
I'm a Super CSV developer. You're the first person I've heard of who's using CsvDozerBeanWriter with their own DozerBeanMapper - great to hear that feature is useful :)
So what's the goal of being 'data driven'? It sounds like you want your code to be really generic, so you can alter the CSV just by changing the XML. Is that right? Of course, you can't configure the cell processors dynamically...or are you trying to do that too!!??
I'd take a look at the MappingMetadata API of Dozer, which you can access by calling getMappingMetadata() on the DozerBeanMapper. I've never used it, but it looks like you could derive the column names this way (though you'd probably be limited to the field names).
Otherwise, you'll have to parse the XML file yourself (I'd probably use XPath). You'd have to do it this way if you want to use some other metadata in the XML for the column name.

how to read sdef file

I am trying with NSArray.arrayWithContentsOfFile_("bla.sdef") but that returns None.
I also tried NSDictionary.dictionaryWithContentsOfFile_("bla.sdef") but that also returns None.
I am trying to get a NSDictionary object in the end in a form where parts of it are conforming to the dict for NSScriptCommandDescription initWithSuiteName:commandName:dictionary:.
(Note: I don't want to know here how to load scripting definitions into NSScriptSuiteRegistry. I really just want to know here how to read the sdef-file.)
Those methods are for reading property-list files. An sdef file is not a property list; it follows a different, purpose-specific XML schema, defined in sdef(5).
I don't think there is a public API for reading sdef files directly into a dictionary or more scripting-specific object; you'll need to do it yourself using an XML parser (either one of Cocoa's or one of Python's).

What is the opposite of JAXB? i.e. generating XML FROM classes?

I am currently designing a solution to a problem I have. I need to dynamically generate an XML file on the fly using Java objects, in the same way JAXB generates Java classes from XML files, however the opposite direction. Is there something out there already like this?
Alternatively, a way in which one could 'save' a state of java classes.
The goal I am working towards is a dynamically changing GUI, where a user can redesign their GUI in the same way you can with iGoogle.
You already have the answer. It's JAXB! You can annotate your classes and then have JAXB marshal them to XML (and back) without the need to create an XML schema first.
Look at https://jaxb.dev.java.net/tutorial/section_6_1-JAXB-Annotations.html#JAXB%20Annotations to get started.
I don't know, if this is exactly what you're looking for, but there's the java.beans.XMLEncoder:
XMLEncoder enc = new XMLEncoder(new FileOutputStream(file));
enc.writeObject(obj);
enc.close();
The result can then be loaded by XMLDecoder:
XMLDecoder dec = new XMLDecoder(new FileInputStream(file));
Object obj = dec.readObject();
dec.close();
"generate xml from java objects:"
try xtream.
Here's what is said on the tin:
No mappings required. Most objects can be serialized without need for specifying mappings.
Requires no modifications to objects.
Full object graph support
For saving java object state:
Serialization is the way to do this in Java

Generate Ruby Classes from XSD

Is there a way to generate Ruby classes (maybe even ActiveResource classes) from an XSD so that they contain a way to serialize the classes to xml valid for the initial XSD?
I know that soap4r has xsd2ruby but it appears that the generated ruby classes cannot be easily serialized to xml.
Shameless self promotion (hope this is okay on stackoverflow) but I'm working on an open source project to do just that
Its still a work in progress (feel free to send patches) but the ultimate goal is to convert XSD to/from Ruby classes (which it does now) and convert XML conforming to that XSD to/from instances of those classes.
Though this was asked a while ago, I came across a solution and thought it might help folks in the future.
My need was similar. I have a .xsd from a colleague and would like to generate a class file from it. My hope is that I'll be able to easily marshall the object and pass it to his RESTful end-point, where his Java server will unmarshall the payload and dynamically build the object on his side with no additional effort.
The solution I found was to get the soap4r from https://github.com/rubyjedi/soap4r. I made the two *.rb files in the bin directory executable and then ran:
bin/xsd2ruby.rb --xsd <source>.xsd --classdef <filename_prefix>
This generated a new file with each of the xsd:complexType implemented as a class. All other complex type were also generated with the correct inheritance relationships and all xsd:element was defined as an instance variable and a class initializer also defined.
Running xsd2ruby.rb by itself yielded the options:
~/src/test/soap4r:bin/xsd2ruby.rb
Usage: bin/xsd2ruby.rb --xsd xsd_location [options]
xsd_location: filename or URL
Example:
bin/xsd2ruby.rb --xsd myapp.xsd --classdef foo
Options:
--xsd xsd_location
--classdef [filenameprefix]
--mapping_registry
--mapper
--module_path [Module::Path::Name]
--force
--quiet
For the sake of completeness, I extended my class with the following (this is a "Prospect" class):
class Prospect
include Enumerable
def each(&block)
self.instance_variables.collect{|v| (v.gsub /#/, '').to_sym }.each(&block)
end
end
This let me use it as the body of an Net::HTTP::Post request.
To the question of a free to_xml: I haven't found it. The ruby Object comes with a to_yaml and to_json out of the box, but I've not found any simple conversion to XML. So it came down to a roll my own "to_xml".
Hope this helps.
It appears that this might work.
require 'xsd/mapping'
XSD::Mapping.obj2xml(xsdBasedObject)

Resources