Many to one mapping in Mule - mule

Example I have an input xml,
<root>
<first>
<a>2</a>
</first>
<first>
<a>3</a>
</first>
<first>
<a>4</a>
</first>
</root>
That should be mapped to,
<root>
<a>2</a>
<a>3</>
<a>4</a>
</root>
I already have output xsd defined that is derived from second xml above but I don't see the mapping in my target because it is one level.
First xml has 3 level and second one is 2 level. So I could not map the child element mapping.
Look at the Branch tangs in the attached image.

You just need to set a mapping where for each input.first -> for each input.a create a output.a.
This is doine using the element mapping controls at the top center (over the lines).

Related

XSL : Loop through a node having multiple nodes and find the attributes having same value and merge them in to one cell

Hi I have below sample xml
<root>
<test>
<tester name="sai" text="test passed">
<tester name="rahul" text="test failed">
<tester name="sai" text="inprogress">
<tester name="rahul" text="not attended">
<tester name="sai" text="test failed">
</test>
</root>
From the above xml I wanted to find the attributes having same names and out put to html by merging in to one cell with the corresponding text attribute values.
Table should have
Sai with rowspan (auto calculate) and corresponding text attribute values in 2nd column
Can any one help with xsl code please

Mule datamapper: Mapping a value to an attribute of right hand side

I have an xml like:
<name>Mule</name>
<company>mulesoft</company>
How can I map using datamapper to get result like:
<details name="Mule" company="mulesoft" />
I tried but datamapper never shows the attributes to map.
I am using Mule 3.5.1
you need to either supply the schema or provide an example for both sides.
For example use the following as the sample source. DataMapper will generate the XSD based on the example file:
<enity>
<name>Mule</name>
<company>mulesoft</company>
</enity>
Right side do the same but use
<company>
<details name="Mule" company="mulesoft" />
</company>
Then click Create Mappings and you should see the mappings to your attributes.

Can this XML be represented in CSV - Objective C

I have following structure of an XML can we convert this into a CSV(ideally for Objective-C)
<root>
<Parent>
<Name>somename</Name>
<Age>20</Age>
<Child>
<ChildItem1>somevalue</ChildItem1>
<ChildItem2>somevalue</ChildItem2>
</Child>
<Child>
<ChildItem1>somevalue</ChildItem1>
<ChildItem2>somevalue</ChildItem2>
</Child>
</Parent>
<Parent>
<Name>somename</Name>
<Age>20</Age>
<Child>
<ChildItem1>somevalue</ChildItem1>
<ChildItem2>somevalue</ChildItem2>
</Child>
<Child>
<ChildItem1>somevalue</ChildItem1>
<ChildItem2>somevalue</ChildItem2>
</Child>
</Parent>
</root>
The problem i am facing is with the List formation of the nodes.
Thanks in advance
Edited : My Problem is i need to get the XML above as a result of CSV/Excel spread sheet, but dont know how to create such a format of cells in it.
CSV describes a grid of data.
XML describes a tree of data.
The only XML that could be directly converted to CSV is one with a root node, containing one or more elements of the same type, each of which contained the same number and types of elements as children.
This XML doesn't fit that criteria, so you would need to come up with explicit rules to convert the data structure to CSV and back. If every parent element contains exactly two child elements (which is unlikely in real data, but holds for the example) then you could just flatten the children.

Not able to get desired output while generating xml files from SQL query from SQL Server

I am executing this query
select category "ROOT/category",
question "Category/question",
option1 "Category/option1"
from testDB2 for XML PATH ('ROOT') , ELEMENTS
Presently the database has three entries and the xml file i get is this
<ROOT>
<ROOT>
<category>maths</category>
</ROOT>
<Category>
<question>2+2?</question>
<option1>1</option1>
</Category>
</ROOT>
<ROOT>
<ROOT>
<category>maths</category>
</ROOT>
<Category>
<question>100*0</question>
<option1>0</option1>
</Category>
</ROOT>
<ROOT>
<ROOT>
<category>chemistry</category>
</ROOT>
<Category>
<question>H2O?</question>
<option1>water </option1>
</Category>
</ROOT>
I do not want this, i want a file with just one main Parent node and rest of them as its child and each child can be parent for other child nodes, but there should be just one single main Parent node, in this case each row is a separate parent and there is no main or single parent
I hope I am able to tell my question properly. Thanks
try something like this:
select category,
question,
option1
from testdb2
for xml raw('Category'), elements, root('Categories')
for xml raw: this will make a node for each row in your table, with every column an attribute for that node
for xml raw('user'): this is the same as xml raw, but you specify the name of the nodes
for xml raw('user') elements: you swith from a attribute view to a node view. every column will be a node in your row node
root('Users'): you can use this to name your parent root
hope this helps
I think you want to use the FOR XML AUTO mode to shape your output.
Not 100% sure what it is you really want, but how about this:
SELECT
category '#Name',
question "Category/question",
option1 "Category/option1"
FROM
dbo.testDB2
FOR XML PATH('Category'), ROOT('ROOT')
Does that get closer to what you want? If I'm not mistaken (can't test right now), this should give you something like:
<ROOT>
<Category Name="maths">
<question>100*0</question>
<option1>0</option1>
</Category>
<Category Name="chemistry">
<question>H2O?</question>
<option1>water </option1>
</Category>
</ROOT>
If not - could you post a few sample rows of data, and what you expect to get from your SELECT in the end??
Marc

Import Xml nodes as Xml column with SSIS

I'm trying to use the Xml Source to shred an XML source file however I do not want the entire document shredded into tables. Rather I want to import the xml Nodes into rows of Xml.
a simplified example would be to import the document below into a table called "people" with a column called "person" of type "xml". When looking at the XmlSource --- it seem that it suited to shredding the source xml, into multiple records --- not quite what I'm looking for.
Any suggestions?
<people>
<person>
<name>
<first>Fred</first>
<last>Flintstone</last>
</name>
<address>
<line1>123 Bedrock Way</line>
<city>Drumheller</city>
</address>
</person>
<person>
<!-- more of the same -->
</person>
</people>
I didn't think that SSIS 2005 supported the XML datatype at all. I suppose it "supports" it as DT_NTEXT.
In any case, you can't use the XML Source for this purpose. You would have to write your own. That's not actually as hard as it sounds. Base it on the examples in Books Online. The processing would consist of moving to the first child node, then calling XmlReader.ReadSubTree to return a new XmlReader over just the next <person/> element. Then use your favorite XML API to read the entire <person/>, convert the resulting XML to a string, and pass it along down the pipeline. Repeat for all <person/> nodes.
Could you perhaps change your xml output so that the content of person is seen as a string? Use escape chars for the <>.
You could use a script task to parse it as well, I'd imagine.