How to convert XmlElement/XmlDocument to Text? I am working on Outsystems(Java)

How to convert XmlElement/XmlDocument to Text? I am working on Outsystems(Java)

  
How to convert XmlElement/XmlDocument to Text? I am working on Outsystems(Java)
Solution
Good morning,
Have you tried this?


Solution
Hey Very good morning,

Thanks for your response. Your response is helpful and worked partially.
As a first step I loaded the xml and used XmlDocument_Save() to see whether the xml document is created or not. This step is successful and I am able to see the complete document xml.

The second step is failing, may be I am dong some thing wrong. As part of second step, I am trying to retrieve the part of xml using xpath. After I used XmlDocument_SelectNodes() by providing xpath, calling XmlDocument_Save() is giving me the empty string.

I am not sure whether the call to XmlDocument_SelectNodes() has failed or XmlDocument_Save() failed converting document to xml. Appreciate your response.
I noticed that, XmlDocument_Save() is working for XmlDocument only. Whereas, XmlDocument_SelectNodes()
is returing XmlNodes, that is the reason why I am getting empty string.
Still my problem remains unsolved. Is there any better solution than this or any alternate solution for my problem ?
Hi Raj,

Once  you have XmlNodes, you can use the other actions in the extension, to retrieve selected parts of those XmlNodes as text, such as XML_GetAttributeValue.

Joao
XML_GetAttributeValue is returning only the tag values of the xml, but I want xml tags along with the values in the xml tags. I thought it would work.
And also, I don't think XML_GetAttributeValue() can be used to get the xml in the specified xpath. This method is used to retrieve attribute values.
Hi Raj,

Do you want to save generated xml document as one text file from selected node ?
Hello Raj,

You can use OTHER ACTIONS in the extension to retrieve the XML tags and use XPath expressions.
You need to look at the list of actions in the XML extension to find what you are looking for.

Joao
Suraj Borade wrote:
Hi Raj,

Do you want to save generated xml document as one text file from selected node ?
 
 Yes Suraj, I want merge two xmls and want to save the final xml as text.
João Santos wrote:
Hello Raj,

You can use OTHER ACTIONS in the extension to retrieve the XML tags and use XPath expressions.
You need to look at the list of actions in the XML extension to find what you are looking for.

Joao
 Hey João Santos,

Thanks for your reply.

As you said may be I am missing something. My requirement is simple, I want to merge 2 xmls(xml1 and xml2).
Get subset of xml1 using xpath and append it to xml2 at a specified path and finally convert the xml3 to text.

I hope this can be achieved using XML extension. But I am going clueless by looking at the bigger picture of my goal. If possible can you give some clues?
 
I haven't done exactly what you are asking for. Looking at the XML extension methods, I would try XMLDocument_SelectSingleNode, XMLDocument_New, XMLDocument_CreateRootElement, XML_AppendChildElement, and XMLDocument_Save.
A XSL_Transform may simplify some of the steps.
That's as much as I can try to help. 

HI João Santos,

I tried to achieve my goal, but it is not possible to achieve the same with XML extension methods.
Any way thanks for your reply.

I'm trying to do something very similar, and it's something that seems like it should be easy. The use case is returning the full outer XML of an XML element - or to clone a node.  For example, if I have an XML document that looks like this:


<MyZoo>

<MyAnimals>

<Animal id="1">

<Species>Lion</Species>

<Name>Leo</Name>

<Age>12</Age>

</Animal>

<Animal id="2">

<Species>Bear</Species>

<Name>Smokey</Name>

<Age>3</Age>

</Animal>

</MyAnimals>

</MyZoo>


Say I want to return to a user one distinct animal.  I can use the XML extension to get a single element:


<Animal id="2">

<Species>Bear</Species>

<Name>Smokey</Name>

<Age>3</Age>

</Animal>


But how do I get that XML returned is text? I don't want the entire document returned.  I could technically almost rebuild the XML by creating a new XML document, cycling through the nodes of the old document, creating elements of the right name, etc.  I'm not sure how I would get all of the attributes of a specific node, though.  In the example case, I would lose the id attribute of the first node.


And in the real-life use case I'm working with, I don't know the structure of the XML underneath the element I'm trying to clone, so I wouldn't be able to map each attribute by name.

Is my only option to use XSL?  I know how to do this in C#, but I'm trying not to write another extension.