Tuesday, September 1, 2009

Getting Started with Axiom/CPP

WSF/CPP comes with its own XML processing model which is Axiom. If you are already familiar with either Axiom/Java or Axiom/C it would not be difficult to grasp how to use Axiom/CPP.

Lets have a look at an small example. Say we want to construct an XML as follows.

<WSO2 xmlns:ns1="http://wso2.org">

<projects>

<WSF>

<WSFCPP>http://wso2.org/projects/wsf/cpp</WSFCPP>

<WSFPHP>http://wso2.org/projects/wsf/php</WSFPHP>

</WSF>

</projects>.

</WSO2>

Lets construct this xml using Axiom/CPP.

First call the Environment::initialize() method to initialize WSF/CPP.

 

Now create OMElement in the corresponding order. You can pass the parent element to the constructor of the child element. The code is self explanatory.

int main()

{

  Environment::initialize("test.log",AXIS2_LOG_LEVEL_TRACE);

   OMElement *wso2 = new OMElement(NULL,"WSO2", new OMNamespace("http://wso2.org","ns1"));
    OMElement *projects = new OMElement(wso2, "projects");;
    OMElement *wsf = new OMElement(projects,"WSF");
    OMElement *wsfcpp = new OMElement(wsf, "WSFCPP");
    wsfcpp->setText("
http://wso2.org/projects/wsf/cpp");
    OMElement *wsfphp = new OMElement(wsf, "WSFPHP");
    wsfphp->setText("
http://wso2.org/projects/wsf/php");

    cout<<wso2;
    delete wso2;

   return 0;

}

No comments:

Post a Comment