Help required with BizTalk mapping - c#

I am trying to get the data from input xml message using functoids. But this doesn't seem to work. Below is my XML snippet
<?xml version="1.0" ?>
<ROOT>
<COMPANIES>
<COMPANY>
<NAME>FOO CORP</name>
</COMPANY>
<COMPANY>
<NAME>ACME CORP</name>
</COMPANY>
</COMPANIES>
<INFORMATIONS>
<INFORMATION>
<TESTING>
<TESTS>
<NAME>1221</NAME>
<TEST>
<TEXT>I AM SAM</TEXT>
</TEST>
</TESTS>
<TESTS>
<NAME>21</NAME>
<TEST>
<TEXT>FADFDF</TEXT>
</TEST>
</TESTS>
<TESTS>
<NAME>3001</NAME>
<TEST>
<TEXT>SGFGSDFG</TEXT>
</TEST>
</TESTS>
<TESTS>
<NAME>4569</NAME>
<TEST>
<TEXT>12312</TEXT>
</TEST>
</TESTS>
</TESTING>
<INFORMATION>
</INFORMATIONS>
</ROOT>
First I am trying to loop through COMPANY and get the NAME "ACME CORP". but which ever functoid i use (scripting, string extract etc) I always get the FOO CORP. I even tried inline XSLT but that also doesn't seem to work. Any idea how to get the 2nd COMPANY name?
Secondly, I have mapped <TEXT> directly to <node> in my destination schema. What i get is only 2 values from <TEXT>. Not all the <TEXT> are mapped to my <node>. Output i am getting is
I don't get is
I AM SAM
FADFDF
I don't get
<node>SGFGSDFG</node>
<node>12312</node>
Any one knows how i could get the values?
Thanks in advance
cheers,
Karthik

Q1: How to get the NAME of the second COMPANY?
1) Add Iteration functoid (Advanced Functoids) and connect to COMPANY node in your source schema
2) Add Equal functiod (Logical Functoids) and connect to Iteration functoid
3) Configure Equal functoid; add constant value 2
4) Add Value Mapping (Flattening) functoid (Advanced Functoids)
5) Connect output of Equal to input of Value Mapping
6) Connect NAME emlement of source schema to input of Value Mapping
7) Connect output of Value Mapping to destination schema element
Q2: Not all source TEXT elements are transformed to destination node
This seems to be a side effect of your mapping concering Q1 and I cannot reproduce your error.
Check minOccurs and maxOccurs of your source and destination schema for the elements/nodes in question.

Related

how to delete root tag in xml C#

hi following XML is my input XML
<?xml version="1.0" encoding="utf-8"?>
<units xmlns="http://www.elsevier.com/xml/ani/ani" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ce="http://www.elsevier.com/xml/ani/common" xsi:schemaLocation="http://www.elsevier.com/xml/ani/ani http://www.elsevier.com/xml/ani/ani512-input-CAR.xsd">
<unit type="journal" xmlns="">
<unit-info>
<timestamp>2017-01-08T02:03:14Z</timestamp>
<order-id>12535892</order-id>
<parcel-id>none</parcel-id>
<unit-id>4756202</unit-id>
</unit-info>
<unit-content>
<bibrecord>
<item-info>
<status state="new" stage="S300" />
</item-info>
<head>
<citation-info>
<citation-type code="jo" />
<citation-language xmllang="ENG" />
<abstract-language xmllang="ENG" />
<author-keywords>
<author-keyword>Stroke</author-keyword>
<author-keyword> cerebral ischaemia</author-keyword>
<author-keyword> Neuro-protection</author-keyword>
<author-keyword> Neuro-protective agents</author-keyword>
</author-keywords>
</citation-info>
<citation-title xmllang="ENG" original="y">
<titletext>PATHOGENESIS AND NEURO-PROTECTIVE AGENTS OF STROKE</titletext>
</citation-title>
<abstracts>
<abstract>
<cepara>ABSTRACT: Stroke remains worlds second leading cause of mortality; and globally most frequent cause of long-lasting disabilities. The ischaemic pathophysiologic cascade leading to neuronal damage consists of peri-infarct depolarization, excitotoxicity, inflammation, oxidative stress, and apoptosis. Despite plethora of experimental evidences and advancement into the development of treatments, clinical treatment of acute stroke still remains challenging. Neuro-protective agents, as novel therapeutic strategy confer neuro-protection by targeting the pathophysiologic mechanism of stroke. The aim of this review is discussion of summary of the literature on stroke pathophysiology, current preclinical research findings of neuroprotective agents in stroke and possible factors that were responsible for the failure of these agents to translate in human stroke therapies.</cepara>
</abstract>
</abstracts>
<correspondence>
<person>
<ceinitials>M.</ceinitials>
<cesurname>Mubarak</cesurname>
</person>
<affiliation>
<organization> Bayero University Kano</organization>
<organization> Nigeria. Email: mubarakmahmad#yahoo.com</organization>
</affiliation>
</correspondence>
<root>
<author Seq="0">
<Inital>A.El</Inital>
<Surname>Khattabi</Surname>
<Givenname>Abdelkrim</Givenname>
</author>
</root>
</head>
</bibrecord>
</unit-content>
from this xml i need to delete root tag alone but i need all child element
<author Seq="0">
<Inital>A.El</Inital>
<Surname>Khattabi</Surname>
<Givenname>Abdelkrim</Givenname>
</author>
how to delete root tag alone. For this i followed following code
XDocument CarXML = new XDocument();
CarXML.Add(Root);
CarXML.Descendants("root").Remove();
CarXML.Save(#"CAR.XML");
But this code delete all xml tag. How to delete root element alone. i need child element
CarXML.ReplaceNodes(CarXML.Descendants("author").FirstOrDefault());
This replaces the whole content of the XML with the first descendant named author.

Web Service List Record

Below is my result from web service, how can I change the record name so that it's uniquely identified? e.g. Record1, Record2, Record3.
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Record> /*How to change this Record to Record1*/
<item>
Buffalo DriveStation Combo 3.5 inch External Hard Drive USB 2.0 1.5TB Quadra
</item>
<qty>1</qty>
<qtyapproved>1</qtyapproved>
<availability>0</availability>
<description>Returned</description>
<itemdescription>-</itemdescription>
<id>188</id>
</Record>
<Record>
<item>eSataII HDD Docking with 1TB 3.5 inch hard disk</item>
<qty>1</qty>
<qtyapproved>1</qtyapproved>
<availability>0</availability>
<description>Returned</description>
<itemdescription/>
<id>184</id>
</Record>
</ArrayOfRecord>
Instead of changing the record name include a unique column in the resultset being returned by the web service, you can use a sequence number if you do not have any unique column.
For example you can add itemId a new column in Record
<Record> /*How to change this Record to Record1*/
<itemId>1</itemId>
<item>
Buffalo DriveStation Combo 3.5 inch External Hard Drive USB 2.0 1.5TB Quadra
</item>
<qty>1</qty>
<qtyapproved>1</qtyapproved>
<availability>0</availability>
<description>Returned</description>
<itemdescription>-</itemdescription>
<id>188</id>
</Record>

Lost prefix's definitions after deserialization of WCF message

I develop WCF-client. My client should validate incoming messages.
One of the messages has the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>...</SOAP-ENV:Header>
<SOAP-ENV:Body>
<OpDescriptionResponse>
<Field Name="DateTime" Type="xsd:dateTime">
</OpDescriptionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
In this case the client should validate: the field "DateTime" has type "dateTime" from namespace "http://www.w3.org/2001/XMLSchema".
This response is deserialized in structure containing array of XmlElement.
But I have an issue: after message is deserialized and I received corresponding variable, containing all Field nodes I can't determine value of prefix "xsd", i.e. if I take any elementof type XMLElement corresponding to Field node in reply and call element.GetNamespaceOfPrefix("xsd") I get empty string as result.
How can I get prefix's definitions are saved after deserialization?
Help me please to overcome this issue.
In order to influence the namespace/prefix, you need to use XmlSerializerNamespaces.
The following code provides a rough reference:
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("prefixHere", "http://namespace.here/");
XmlSerializer tempSerializer = new XmlSerializer(messageObject.GetType());
tempSerializer.Serialize(Console.Out, messageObject, namespaces);
Regards,

Preparing XSD of a complex xml

Thank you all for suggesting things and helping whenever in need.
Yesterday I was trying to develop and web app in asp.net 4.0 where I needed to parse the data from xml and save it in database. But before that I will also have to validate it.
I tried using .net provided tool xsd.exe to generate the schema file, but I dont know how will it know to mark which nodes or attributes are compulsory?
Like in my xml below items are mandatory
Root node <Market>
<Login> and its sub element
<ProductType> and its <ProductTypeID/>
The attribute DML is mandatory but should have only 3 values NONE, PUT or MODIFY
<ProductType> may or may not have <ProductItem>
If <ProductItem> is present then it should have <ProductItemID>
<ProductItem> may or may not have <Brand>
If <Brand> is present then it should have <BrandID>
Below is my xml
<?xml version="1.0" encoding="utf-8" ?>
<Market>
<Login>
<LoginId />
<Password />
</Login>
<ProductType DML="NONE">
<ProductTypeID/>
<Name/>
<Detail/>
<ProductItem DML="PUT">
<ProductItemID/>
<Name/>
<Detail/>
<Brand DML="PUT">
<BrandID/>
<Name/>
<Detail/>
</Brand>
<Brand DML="MODIFY">
<BrandID/>
<Name/>
<Detail/>
</Brand>
</ProductItem>
<ProductItem DML="MODIFY">
<ProductItemID/>
<Name/>
<Detail/>
</ProductItem>
</ProductType>
</Market>
How and where should I specify all the mandatory and optional parameters, so that my xsd is generated as per the requirement.
Thanks,
M.
xsd.exe can only try to infer, which elements/attributes are in you xml, but it cannot find out which information is mandatory. But this is a good startingpoint.
use a graphical XML_Schema_Editor to edit the genrated xsd to mark your mandatory fields. That is much easier than learning the xsd-language
I don't think XSD support nested XML. I would try to load the XML into an XmlDocument and check mandatory fields manually.

Pivotviewer's .cxml parsing

I'm trying to do very simple operations on a .cxml file. As you know it's basically an .xml file. This is a sample file I created to test the application:
<?xml version="1.0" encoding="utf-8"?>
<Collection xmlns:p="http://schemas.microsoft.com/livelabs/pivot/collection/2009" SchemaVersion="1.0" Name="Actresses" xmlns="http://schemas.microsoft.com/collection/metadata/2009">
<FacetCategories>
<FacetCategory Name="Nationality" Type="LongString" p:IsFilterVisible="true" p:IsWordWheelVisible="true" p:IsMetaDataVisible="true" />
</FacetCategories>
<!-- Other entries-->
<Items ImgBase="Actresses_files\go144bwo.0ao.xml" HrefBase="http://www.imdb.com/name/">
<Item Id="2" Img="#2" Name="Anna Karina" Href="nm0439344/">
<Description> She is a nice girl</Description>
<Facets>
<Facet Name="Nationality">
<LongString Value="Danish" />
</Facet>
</Facets>
</Item>
</Items>
<!-- Other entries-->
</Collection>
I can't get any functioning simple code like:
XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("Item"))
{
...
}
The test on a generic xml is working. The cxml file is correctly loaded in document.
While watching the expression:
document.Descendants("Item"), results
the answer is:
Empty "Enumeration yielded no results" string
Any hint on what can be the error? I've also add a quick look to get Descendants of Facet, Facets, etc., but there are no results in the enumeration. This obviously doesn't happen with a generic xml file I used for testing. It's a problem I have with .cxml.
Basically your XML defines a default namespace with the xmlns="http://schemas.microsoft.com/collection/metadata/2009" attribute:
That means you need to fully qualify your Descendants query e.g.:
XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("{http://schemas.microsoft.com/collection/metadata/2009}Item"))
{
...
}
If you remove the default namespace from the XML your code actually works as-is, but that is not the aim of the exercise.
See Metadata.CXML project under http://github.com/Zoomicon/Metadata.CXML sourcecode for LINQ-based parsing of CXML files.
Also see ClipFlair.Metadata project at http://github.com/Zoomicon/ClipFlair.Metadata for parsing one's CXML custom facets too
BTW, at http://ClipFlair.codeplex.com can checkout the ClipFlair.Gallery project for how to author ASP.net web-based forms to edit metadata fragments (parts of CXML files) and merge them together in a single one (that you then convert periodically to DeepZoom CXML with PAuthor tool from http://pauthor.codeplex.com).
If anyone is interested in doing nesting (hierarchy) of CXML collections see
http://github.com/Zoomicon/Trafilm.Metadata
and
http://github.com/Zoomicon/Trafilm.Gallery

Categories

Resources