You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Dean Povey <De...@quest.com> on 2007/07/09 08:35:16 UTC

Problem using XMLHelper

Hi All,

I am running across a problem using XMLHelper to generate XML from
arbitrary DataObjects.  If I create a bare DataObject it seems to work
fine. If I use a datagraph it falls in a heap.

Here is an example that illustrates the problem:

import java.io.IOException;

import org.apache.tuscany.sdo.util.SDOUtil;

import commonj.sdo.DataGraph;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.helper.DataFactory;
import commonj.sdo.helper.TypeHelper;
import commonj.sdo.helper.XMLHelper;

public class Example {

	
	private static final String NSURI = "http://example.com/";

	public static void main(String[] args) throws IOException {
		// Create an arbitrary type
		DataObject exampleType =
DataFactory.INSTANCE.create("commonj.sdo",
				"Type");
		exampleType.set("uri", NSURI);
		exampleType.set("name", "example");
		DataObject exampleProperty =
exampleType.createDataObject("property");
		exampleProperty.set("name", "property");
		exampleProperty.set("type",
TypeHelper.INSTANCE.getType("commonj.sdo", "String"));
		Type type = TypeHelper.INSTANCE.define(exampleType);
		
		// Success
		DataObject ok = DataFactory.INSTANCE.create(type);
		ok.set("property", "Helloworld");
		XMLHelper.INSTANCE.save(ok, NSURI, "example-ok",
System.out);
		
		// Failure
		System.out.println();
		DataGraph dg = SDOUtil.createDataGraph();
		DataObject fails = dg.createRootObject(type);
		fails.set("property", "Helloworld");
		XMLHelper.INSTANCE.save(fails, NSURI, "example-fail",
System.out);
		
	}
}


This generates the output:

<?xml version="1.0" encoding="ASCII"?>
<example-ok xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://example.com/" xsi:type="example"
    property="Helloworld"/>
<?xml version="1.0" encoding="ASCII"?>
<example-fail xmlns="http://example.com/" href="root.xml#/"/>

In the later case it has failed to correctly write out the XML.

Is there something I am missing or doing wrong here?

Dean.



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org