You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mona Yazbeck <mo...@hec.ca> on 2006/05/30 21:10:32 UTC

Help on creating a MessageElement

Hello!

I need help on this! I am trying make an update operation on a web services. I used WSDL2Java to create TestCase class. The testcase class use a method taking in parameter two value, a string and a updateListItemsUpdates... wich is in fact a MessageElement

binding.updateListItems(new java.lang.String(), new lists.ws.UpdateListItemsUpdates());

I am changing this line to put value in it and I wanna pass this:

<Method ID='1' Cmd='New'>
    <Field Name='Title'>Family name</Field>
    <Field Name='FirstName'>First Name</Field>
    <Field Name='Email'>address</Field>
</Method>

as my second argument, but I have no idea how to put this in a MessageElement[].

In .NET I was using this and it was working perfectly:
Dim xDoc As New System.Xml.XmlDocument

Dim xBatch As System.Xml.XmlElement = xDoc.CreateElement("Batch")

xBatch.SetAttribute("OnError", "Return")

xBatch.InnerXml = "<Method ID='1' Cmd='New'><Field Name='Title'>Last Name</Field><Field Name='FirstName'>First Name</Field><Field Name='Email'>address</Field></Method>"

Dim xReturn As System.Xml.XmlNode = oListWS.UpdateListItems("Contacts", xBatch)


Any help would be greatly appreciated! 

Below is the complex type from my WSDL.
<s:element name="UpdateListItems">

<s:complexType>

<s:sequence>

<s:element minOccurs="0" maxOccurs="1" name="listName" type="s:string" />

<s:element minOccurs="0" maxOccurs="1" name="updates">

<s:complexType mixed="true">

<s:sequence>

<s:any />

</s:sequence>

</s:complexType>

</s:element>

</s:sequence>

</s:complexType>

</s:element>



Thanks!

Re: Help on creating a MessageElement

Posted by Mona Yazbeck <mo...@hec.ca>.
It's working now, thanks for the help!

I had to put my variable "namespaceUri" to empty to get it work.

And I had to call the getAsString() method from the first element of my 
messageelement (me[0].getAsString();)

Thanks again, it is really appreciated!

Mona


----- Message d'origine ----- 
De : "Mona Yazbeck" <mo...@hec.ca>
À : <ax...@ws.apache.org>
Envoyé : 31 mai 2006 16:25
Objet : Re: Help on creating a MessageElement


> Thanks! But one more question, I have to put this in the message element:
>
> <Batch OnError="Return">
>    <Method ID="1" Cmd="New">
>        <Field Name="Title">nom</Field>
>        <Field Name="FirstName">FirstName</Field>
>        <Field Name="Email">email@domain.com</Field>
>    </Method>
> </Batch>
>
> I wrote this, but I know I got a mistake somewhere... I don't think it 
> output the right XML. (I am trying to use getAsString() to see the output, 
> without success)
>
> MessageElement me[] = new MessageElement[1];
> me[0] = new MessageElement (new QName(namespaceUri, "Batch"));
> me[0].addAttribute(namespaceUri, "OnError", "Return");
> MessageElement method = (MessageElement)me[0].addChildElement("Method");
> method.addAttribute(namespaceUri, "ID", "1");
> method.addAttribute(namespaceUri, "Cmd", "New");
> MessageElement title = (MessageElement)method.addChildElement("Title");
> title.addTextNode("Nom");
> MessageElement firstname = 
> (MessageElement)method.addChildElement("FirstName");
> firstname.addTextNode("First Name");
> MessageElement email = (MessageElement)method.addChildElement("Email");
> email.addTextNode("email@domain.com");
>
> Thank you so much.
>
> Mona
>
>
> ----- Message d'origine ----- 
> De : "Jaka Mocnik" <ja...@xlab.si>
> À : <ax...@ws.apache.org>
> Envoyé : 31 mai 2006 14:16
> Objet : Re: Help on creating a MessageElement
>
>
>> On Wed, 2006-05-31 at 13:50 -0400, Mona Yazbeck wrote:
>>> Hi Jaka,
>>>
>>> I get a compilation error when trying to call my constructor with the 
>>> root
>>> element. I guess it's because the constructor is waiting for a
>>> MessageElement[] (an array).
>>>         cannot resolve symbol
>>>         symbol: constructor
>>> UpdateListItemsUpdates(org.apache.axis.message.MessageElement)
>> ok, I completely misunderstood you before.
>>
>> so you want to have a MessageElement[] array that represents the
>> children of the Method element you decribe in your original post?
>> simple:
>>
>> MessageElement me[] = new MessageElement[3];
>>
>> now for each me[0..2] create a new MessageElement:
>>
>> me[i] = new MessageElement(new QName(namespaceUri, elementName));
>>
>> add appropriate attributes:
>>
>> me[i].addAttribute(namespaceUri, attributeName, attributeValue);
>>
>> finally, add text content of the element:
>>
>> me[i].addTextNode(contentOfTheElement);
>>
>> I believe this will create the appropriate MessageElements...
>>
>> regards,
>>  jaKa
>>
>> -- 
>> email: jaka@xlab.si
>> w3:    http://fish.homeunix.org/people/jaka
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


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


Re: Help on creating a MessageElement

Posted by Mona Yazbeck <mo...@hec.ca>.
Thanks! But one more question, I have to put this in the message element:

<Batch OnError="Return">
    <Method ID="1" Cmd="New">
        <Field Name="Title">nom</Field>
        <Field Name="FirstName">FirstName</Field>
        <Field Name="Email">email@domain.com</Field>
    </Method>
</Batch>

I wrote this, but I know I got a mistake somewhere... I don't think it 
output the right XML. (I am trying to use getAsString() to see the output, 
without success)

MessageElement me[] = new MessageElement[1];
me[0] = new MessageElement (new QName(namespaceUri, "Batch"));
me[0].addAttribute(namespaceUri, "OnError", "Return");
MessageElement method = (MessageElement)me[0].addChildElement("Method");
method.addAttribute(namespaceUri, "ID", "1");
method.addAttribute(namespaceUri, "Cmd", "New");
MessageElement title = (MessageElement)method.addChildElement("Title");
title.addTextNode("Nom");
MessageElement firstname = 
(MessageElement)method.addChildElement("FirstName");
firstname.addTextNode("First Name");
MessageElement email = (MessageElement)method.addChildElement("Email");
email.addTextNode("email@domain.com");

Thank you so much.

Mona


----- Message d'origine ----- 
De : "Jaka Mocnik" <ja...@xlab.si>
À : <ax...@ws.apache.org>
Envoyé : 31 mai 2006 14:16
Objet : Re: Help on creating a MessageElement


> On Wed, 2006-05-31 at 13:50 -0400, Mona Yazbeck wrote:
>> Hi Jaka,
>>
>> I get a compilation error when trying to call my constructor with the 
>> root
>> element. I guess it's because the constructor is waiting for a
>> MessageElement[] (an array).
>>         cannot resolve symbol
>>         symbol: constructor
>> UpdateListItemsUpdates(org.apache.axis.message.MessageElement)
> ok, I completely misunderstood you before.
>
> so you want to have a MessageElement[] array that represents the
> children of the Method element you decribe in your original post?
> simple:
>
> MessageElement me[] = new MessageElement[3];
>
> now for each me[0..2] create a new MessageElement:
>
> me[i] = new MessageElement(new QName(namespaceUri, elementName));
>
> add appropriate attributes:
>
> me[i].addAttribute(namespaceUri, attributeName, attributeValue);
>
> finally, add text content of the element:
>
> me[i].addTextNode(contentOfTheElement);
>
> I believe this will create the appropriate MessageElements...
>
> regards,
>  jaKa
>
> -- 
> email: jaka@xlab.si
> w3:    http://fish.homeunix.org/people/jaka
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


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


Re: Help on creating a MessageElement

Posted by Jaka Močnik <ja...@xlab.si>.
On Wed, 2006-05-31 at 13:50 -0400, Mona Yazbeck wrote:
> Hi Jaka,
> 
> I get a compilation error when trying to call my constructor with the root 
> element. I guess it's because the constructor is waiting for a 
> MessageElement[] (an array).
>         cannot resolve symbol
>         symbol: constructor 
> UpdateListItemsUpdates(org.apache.axis.message.MessageElement)
ok, I completely misunderstood you before.

so you want to have a MessageElement[] array that represents the
children of the Method element you decribe in your original post?
simple:

MessageElement me[] = new MessageElement[3];

now for each me[0..2] create a new MessageElement:

me[i] = new MessageElement(new QName(namespaceUri, elementName));

add appropriate attributes:

me[i].addAttribute(namespaceUri, attributeName, attributeValue);

finally, add text content of the element:

me[i].addTextNode(contentOfTheElement);

I believe this will create the appropriate MessageElements...

regards,
  jaKa

-- 
email: jaka@xlab.si
w3:    http://fish.homeunix.org/people/jaka



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


Re: Help on creating a MessageElement

Posted by Mona Yazbeck <mo...@hec.ca>.
Hi Jaka,

I get a compilation error when trying to call my constructor with the root 
element. I guess it's because the constructor is waiting for a 
MessageElement[] (an array).
        cannot resolve symbol
        symbol: constructor 
UpdateListItemsUpdates(org.apache.axis.message.MessageElement)

Here's the code I used (sBatch is the XML in a string):
Document document;
DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
ByteArrayInputStream stream=new ByteArrayInputStream(sBatch.getBytes());
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(stream);
Element root = document.getDocumentElement();

org.apache.axis.message.MessageElement xbatch = new 
org.apache.axis.message.MessageElement(root);
UpdateListItemsUpdates obj = new UpdateListItemsUpdates(xbatch);

----

If I want to create the tree manually as I wrote below, how can I add the 
root element and the attributes to it, can I see an example of that?

org.apache.axis.message.MessageElement[] xbatch = new
org.apache.axis.message.MessageElement[3];
 xbatch[0] = new org.apache.axis.message.MessageElement(new
javax.xml.namespace.QName("Title"),"Last Name");
 xbatch[1] = new org.apache.axis.message.MessageElement(new
javax.xml.namespace.QName("FirstName"),"First Name");
 xbatch[2] = new org.apache.axis.message.MessageElement(new
 javax.xml.namespace.QName("Email"),"Email");

Thank again!


----- Message d'origine ----- 
De : "Jaka Mocnik" <ja...@xlab.si>
À : <ax...@ws.apache.org>
Envoyé : 31 mai 2006 11:49
Objet : Re: Help on creating a MessageElement


> On Wed, 2006-05-31 at 11:26 -0400, Mona Yazbeck wrote:
>> Hello
>>
>> I started parsing my XML to DOM, but then, even if I create a new message
>> element with the root of the DOM, I will get an error, because it seems 
>> like
>> I really need a MessageElement as an array since the contructor of my 
>> other
>> method is:
>>
>> public UpdateListItemsUpdates(org.apache.axis.message.MessageElement []
>> _any) {
>>            this._any = _any;
>> }
>>
>> So then, how can I put my XML file in an array of MessageElement?
>>
>> <Method ID='1' Cmd='New'>
>>     <Field Name='Title'>Nom</Field>
>>     <Field Name='FirstName'>Prenom</Field>
>>     <Field Name='Email'>email@domain.com</Field>
>> </Method>
>>
>> I tried this way:
>>
>>  org.apache.axis.message.MessageElement[] xbatch = new
>> org.apache.axis.message.MessageElement[3];
>>  xbatch[0] = new org.apache.axis.message.MessageElement(new
>> javax.xml.namespace.QName("Title"),"Last Name");
>>  xbatch[1] = new org.apache.axis.message.MessageElement(new
>> javax.xml.namespace.QName("FirstName"),"First Name");
>>  xbatch[2] = new org.apache.axis.message.MessageElement(new
>> javax.xml.namespace.QName("Email"),"Email");
>>
>> but I don't know how to put the root element in this kind of structure...
> I was more thinking of parsing the XML in a string, using a
> DocumentBuilder, which yields a document with a single root Element (the
> Method element), you wrap that one in a MessageElement with
>
> me = new MessageElement(root);
>
> and use that one as the parameter updateListItems().
>
> of course you can construct the DOM tree manually as you intended to do
> above, but then create the root message element, add the child elements
> to it and don't forget about the attributes...
>
> regards,
>  jaKa
>
> -- 
> email: jaka@xlab.si
> w3:    http://fish.homeunix.org/people/jaka/
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


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


Re: Help on creating a MessageElement

Posted by Jaka Močnik <ja...@xlab.si>.
On Wed, 2006-05-31 at 11:26 -0400, Mona Yazbeck wrote:
> Hello
> 
> I started parsing my XML to DOM, but then, even if I create a new message 
> element with the root of the DOM, I will get an error, because it seems like 
> I really need a MessageElement as an array since the contructor of my other 
> method is:
> 
> public UpdateListItemsUpdates(org.apache.axis.message.MessageElement [] 
> _any) {
>            this._any = _any;
> }
> 
> So then, how can I put my XML file in an array of MessageElement?
> 
> <Method ID='1' Cmd='New'>
>     <Field Name='Title'>Nom</Field>
>     <Field Name='FirstName'>Prenom</Field>
>     <Field Name='Email'>email@domain.com</Field>
> </Method>
> 
> I tried this way:
> 
>  org.apache.axis.message.MessageElement[] xbatch = new 
> org.apache.axis.message.MessageElement[3];
>  xbatch[0] = new org.apache.axis.message.MessageElement(new 
> javax.xml.namespace.QName("Title"),"Last Name");
>  xbatch[1] = new org.apache.axis.message.MessageElement(new 
> javax.xml.namespace.QName("FirstName"),"First Name");
>  xbatch[2] = new org.apache.axis.message.MessageElement(new 
> javax.xml.namespace.QName("Email"),"Email");
> 
> but I don't know how to put the root element in this kind of structure...
I was more thinking of parsing the XML in a string, using a
DocumentBuilder, which yields a document with a single root Element (the
Method element), you wrap that one in a MessageElement with

me = new MessageElement(root);

and use that one as the parameter updateListItems().

of course you can construct the DOM tree manually as you intended to do
above, but then create the root message element, add the child elements
to it and don't forget about the attributes...

regards,
  jaKa

-- 
email: jaka@xlab.si
w3:    http://fish.homeunix.org/people/jaka/



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


Re: Help on creating a MessageElement

Posted by Mona Yazbeck <mo...@hec.ca>.
Hello

I started parsing my XML to DOM, but then, even if I create a new message 
element with the root of the DOM, I will get an error, because it seems like 
I really need a MessageElement as an array since the contructor of my other 
method is:

public UpdateListItemsUpdates(org.apache.axis.message.MessageElement [] 
_any) {
           this._any = _any;
}

So then, how can I put my XML file in an array of MessageElement?

<Method ID='1' Cmd='New'>
    <Field Name='Title'>Nom</Field>
    <Field Name='FirstName'>Prenom</Field>
    <Field Name='Email'>email@domain.com</Field>
</Method>

I tried this way:

 org.apache.axis.message.MessageElement[] xbatch = new 
org.apache.axis.message.MessageElement[3];
 xbatch[0] = new org.apache.axis.message.MessageElement(new 
javax.xml.namespace.QName("Title"),"Last Name");
 xbatch[1] = new org.apache.axis.message.MessageElement(new 
javax.xml.namespace.QName("FirstName"),"First Name");
 xbatch[2] = new org.apache.axis.message.MessageElement(new 
javax.xml.namespace.QName("Email"),"Email");

but I don't know how to put the root element in this kind of structure...

Thanks again for any help.


----- Message d'origine ----- 
De : "Jaka Mocnik" <ja...@xlab.si>
À : <ax...@ws.apache.org>
Envoyé : 30 mai 2006 15:41
Objet : Re: Help on creating a MessageElement


> On Tue, 2006-05-30 at 15:10 -0400, Mona Yazbeck wrote:
>> Hello!
>>
>> I need help on this! I am trying make an update operation on a web
>> services. I used WSDL2Java to create TestCase class. The testcase
>> class use a method taking in parameter two value, a string and a
>> updateListItemsUpdates... wich is in fact a MessageElement
>>
>> binding.updateListItems(new java.lang.String(), new
>> lists.ws.UpdateListItemsUpdates());
>>
>> I am changing this line to put value in it and I wanna pass this:
>>
>> <Method ID='1' Cmd='New'>
>>     <Field Name='Title'>Family name</Field>
>>     <Field Name='FirstName'>First Name</Field>
>>     <Field Name='Email'>address</Field>
>> </Method>
>>
>> as my second argument, but I have no idea how to put this in a
>> MessageElement[].
> well, you can always try parsing your XML to DOM, then create a new
> MessageElement from the root document Element using the appropriate
> MessageElement constructor. I don't know if that suffices, though...
>
> regards,
>  jaKa
>
> -- 
> email: jaka@xlab.si
> w3:    http://fish.homeunix.org/people/jaka
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


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


Re: Help on creating a MessageElement

Posted by Jaka Močnik <ja...@xlab.si>.
On Tue, 2006-05-30 at 15:10 -0400, Mona Yazbeck wrote:
> Hello!
>  
> I need help on this! I am trying make an update operation on a web
> services. I used WSDL2Java to create TestCase class. The testcase
> class use a method taking in parameter two value, a string and a
> updateListItemsUpdates... wich is in fact a MessageElement
>  
> binding.updateListItems(new java.lang.String(), new
> lists.ws.UpdateListItemsUpdates());
>  
> I am changing this line to put value in it and I wanna pass this:
>  
> <Method ID='1' Cmd='New'>
>     <Field Name='Title'>Family name</Field>
>     <Field Name='FirstName'>First Name</Field>
>     <Field Name='Email'>address</Field>
> </Method>
>  
> as my second argument, but I have no idea how to put this in a
> MessageElement[].
well, you can always try parsing your XML to DOM, then create a new
MessageElement from the root document Element using the appropriate
MessageElement constructor. I don't know if that suffices, though...

regards,
  jaKa

-- 
email: jaka@xlab.si
w3:    http://fish.homeunix.org/people/jaka



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