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.
Related
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).
I am attempting to unmarshal an XML data stream with EclipseLink MOXy with an XPath using the contains function.
When I apply the sample XPath directly to the sample XML data stream I get the correct value returned (Ref_number_1). However, when I unmarshal this using MOXy, the value that is set for refNumber1 is "Ref_number_2".
Does MOXy not support this type of XPath? It would appear that it at least is understanding it because it's not throwing an error, just setting the wrong value.
Anyone have any experience with this sort of thing? Know of a better approach?
Thanks for any help.
Marshal code:
String s = //xml stream from restful service (see xml example below);
StringReader sr = new StringReader(s);
ReferenceNumber refNum = (ReferenceNumber)marshaller.unmarshal(
new StreamSource(sr));
Member annotation:
#XmlPath("Header/ReferenceNumbers/ReferenceNumber[contains(ReferenceNumberType, \"REF_NUMBER_TYPE_1\")]/ReferenceNumber/text()")
private String refNumber1;
XML data:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Header>
<ReferenceNumbers>
<ReferenceNumber>
<ReferenceNumber>Ref_number_1</ReferenceNumber>
<ReferenceNumberType>REF_NUMBER_TYPE_1</ReferenceNumberType>
</ReferenceNumber>
<ReferenceNumber>
<ReferenceNumber>Ref_number_2</ReferenceNumber>
<ReferenceNumberType>REF_NUMBER_TYPE_2</ReferenceNumberType>
</ReferenceNumber>
</ReferenceNumbers>
</Header>
</Document>
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
Currently MOXy does not support XPaths of that form. Currently a conditional check must be on an attribute contained within the element such as (see: http://blog.bdoughan.com/2011/03/map-to-element-based-on-attribute-value.html).
#XmlPath("personal-info/name[#type='first']/text()")
String firstName;
I have entered the following bug so that we improve the validation that we do on our #XmlPath annotation:
http://bugs.eclipse.org/397101
I am also interested in the use case described in your question. Would you mind entering an enhancement requires against the MOXy component for this:
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink
I am attempting to make use of Microsoft's Log Parser 2.2. I am pointing my Log Parser at an XML file. I would like to obtain certain information from the XML file and then reuse this information within the query. I have created some pseudo code below:
GET UNIQUE *WINDOW_NAMES*
FOR EACH *WINDOW_NAME*
{
GET WINDOW_ATTRIBUTE_ONE;
GET WINDOW_ATTRIBUTE_TWO;
}
Would this be possible with Log Parser 2.2?
An extract of the XML document:
<windows>
<window>
<name>
Window One
</name>
<visible>
Visible
</visible>
<stayontop>
True
</stayontop>
</window>
<window>
<name>
Window Two
</name>
<visible>
Visible
</visible>
<stayontop>
False
</stayontop>
</window>
<window>
<name>
Window Three
</name>
<visible>
Invisible
</visible>
<stayontop>
True
</stayontop>
</window>
</windows>
You might use the TPL output format to generate a (set of) queries based on the results of your first query, and then run logparser on the output file.
SQL, in any form, and the LogParser variety especially, is not well-suited for looping. However, if all you're trying to do is get at the data elements, then this query might do the job:
LogParser -i:XML "file.xml#/windows/window"
This will output a table with the fields name, visible, and stayontop, and a row for each "window". You can then save/output this data using one of the LogParser output options (see LogParser -h or the LogParser Windows Help file for more details).
A set of forms (using Zend_Form) that I have been working on were causing me some headaches trying to figure out what was wrong with my XML configuration, as I kept getting unexpected HTML output for a particular INPUT element. It was supposed to be getting a default value, but nothing appeared.
It appears that the following 2 pieces of XML are not equal when used to instantiate Zend_Form:
Snippet #1:
<form>
<elements>
<test type="hidden">
<options ignore="true" value="foo"/>
</test>
</elements>
</form>
Snippet #2:
<form>
<elements>
<test type="hidden">
<options ignore="true">
<value>foo</value>
</options>
</test>
</elements>
</form>
The type of the element doesn't appear to make a difference, so it doesn't appear to be related to hidden fields.
Is this expected or not?
As it was rather quiet on here, I took a look further into the source code and documentation.
On line 259 of Zend_Config_Xml, the SimpleXMLElement object attributes are converted to a string, resulting in:
options Object of: SimpleXMLElement
#attributes Array [2]
label (string:7) I can't see this because
value (string:21) something happens to this
becoming
options (string:21) something happens to this
So, I hunted through the documentation only to find that "value" is a reserved keyword when used as an attribute in an XML file that is loaded into Zend_Config_Xml:
Example #2 Using Tag Attributes in Zend_Config_Xml
"..Zend_Config_Xml also supports two
additional ways of defining nodes in
the configuration. Both make use of
attributes. Since the extends and the
value attributes are reserved keywords
(the latter one by the second way of
using attributes), they may not be
used..."
Thus, it would appear to be "expected" according to the documentation.
I'm not entirely happy that this is a good idea though, considering "value" is an attribute of form elements.
Don't worry about this. The reserved keywords were moved to their own namespace, and the previous attributes were depricated. In Zend Framework 2.0 the non-namespaced attributes will be removed so you can use them again.
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.