Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Add or insert records to XML Repeating Sequence Group
- This topic has 7 replies, 1 voice, and was last updated 8 years, 3 months ago by
community-content.
-
AuthorPosts
-
-
June 1, 2006 at 2:45 PM #13769
The two methods that come to mind first are doing it with text/strings/stringBuilder or with XmlDocument (and maybe a C# helper class).
Where I work, they have a C# helper class with a static method called AddChildDocument:
The C# code is relatively simple:
[code:1:63b3f28f8d] public static XmlDocument AddChildDocument(
XmlDocument parentDocument,
XmlDocument childDocument,
string parentElementName,
string parentNamespace)
{
XmlElement rootElement = null;
XmlNode childRoot = null;
XmlNodeList nodeList = null;if (parentDocument != null && childDocument != null)
{
nodeList = parentDocument.GetElementsByTagName(parentElementName, parentNamespace);if (nodeList != null & nodeList.Count > 0)
{
rootElement = (XmlElement)nodeList.Item(0);
if (rootElement != null)
{
childRoot = childDocument.DocumentElement;
rootElement.InnerXml = rootElement.InnerXml + childRoot.OuterXml;
}
}
}return parentDocument;
}[/code:1:63b3f28f8d] -
June 7, 2006 at 3:05 PM #13770
The C# code has NOTHING to do with a map.
It is called from a Biztalk message assignment shape in an orchestration.The C# must have a strong name, and must be installed in the GAC on the machine where Biztalk server is running.
In your Biztalk project, you make a reference to the assembly (project, right click reference, click \”Browse\” button, find BIN directory where you compiled .DLL to, and select the .DLL.
Since the C# routine is static, you do not need a variable/object to call it.
You will code something like this:
YourNamespace.YourClass.AddChildDocument(
msgParent, msgChild,
\”ParentElement\”, \”http://xxxxx.com/schema\”);Since normal messages are xmlDocuments, I’m pretty sure you can pass them directly where the C# program expects an xmlDocument object.
Eventually, you will probably develop several \”helper\” classes in C#,
so you will probably have something like an XmlHelpersClass, and it may have 5 to 20 methods in it that you can call.-
June 13, 2006 at 8:07 PM #13771
You can test a value in a schema three ways:
1) Promoted field: msgABC(namespace.fieldname)
2) Distinguished field: msgABC.fieldname
3) Use the Xpath function to query the value of the field – this is more complex, but sometimes handy:
strTempValue = xpath(msgABC,\”string(//*fieldname[1])\”).
The problem is that the namespace must often be added and the XPath can get very complex.-
June 15, 2006 at 4:55 PM #13772
Sure, as long as it works for you.
-
June 1, 2006 at 1:17 PM #13773
I have cranked out my Biztalk books and am at a loss as to how to add or insert records into a XML message. I have the initial message which has a repeating sequence group. Depending on the attribute values in the main body, I need to add empty records in the sequence group. I suspect I might be able to do this through the mapper. Even if someone had an example somewhere, on how to add items to a message, I might be able to figure it out.
Here’s the sample XML
<SOWReview>
<ADProduct>True</ADProduct>
<MSProduct>True</MSProduct>
<Reviewer>
<ReviewerName></ReviewerName>
<ReviewerApproved>false</ReviewerApproved>
<ReviewDate xsi:nil=\”true\”></ReviewDate>
<Notes></Notes>
<UserName></UserName>
<ReviewerEmail></ReviewerEmail>
<ReviewerTitle></ReviewerTitle>
<Specialty></Specialty>
</Reviewer>
</SOWReview>For each product that is \”True\” I need to add a specific reviewer, but am not sure how to do this. Any help would be greatly appreciated. Thanks.
-
June 7, 2006 at 12:27 PM #13774
[quote:e1971f0488=\”nwalters\”]The two methods that come to mind first are doing it with text/strings/stringBuilder or with XmlDocument (and maybe a C# helper class).
Where I work, they have a C# helper class with a static method called AddChildDocument:
The C# code is relatively simple:
[code:1:e1971f0488] public static XmlDocument AddChildDocument(
XmlDocument parentDocument,
XmlDocument childDocument,
string parentElementName,
string parentNamespace)
{
XmlElement rootElement = null;
XmlNode childRoot = null;
XmlNodeList nodeList = null;if (parentDocument != null && childDocument != null)
{
nodeList = parentDocument.GetElementsByTagName(parentElementName, parentNamespace);if (nodeList != null & nodeList.Count > 0)
{
rootElement = (XmlElement)nodeList.Item(0);
if (rootElement != null)
{
childRoot = childDocument.DocumentElement;
rootElement.InnerXml = rootElement.InnerXml + childRoot.OuterXml;
}
}
}return parentDocument;
}[/code:1:e1971f0488][/quote:e1971f0488]Hi [color=darkblue:e1971f0488][b:e1971f0488]nwalters[/b:e1971f0488][/color:e1971f0488],
I have the same problem than [color=darkblue:e1971f0488][b:e1971f0488]joswalt[/b:e1971f0488][/color:e1971f0488]…
Your [i:e1971f0488]C#[/i:e1971f0488] code seems to be useful, but where do you put it ? In a [i:e1971f0488]scripting functoid[/i:e1971f0488] in the [i:e1971f0488]BizTalk mapper[/i:e1971f0488] ?
If yes, how can you connect that scripting functoid between source and destination schema ?
I can’t understand…Thanks a lot if you can help me on that point.
-
June 8, 2006 at 12:45 PM #13775
[quote:9f69ecc8b3=\”nwalters\”]The C# code has NOTHING to do with a map.
It is called from a Biztalk message assignment shape in an orchestration.The C# must have a strong name, and must be installed in the GAC on the machine where Biztalk server is running.
In your Biztalk project, you make a reference to the assembly (project, right click reference, click \”Browse\” button, find BIN directory where you compiled .DLL to, and select the .DLL.
Since the C# routine is static, you do not need a variable/object to call it.
You will code something like this:
YourNamespace.YourClass.AddChildDocument(
msgParent, msgChild,
\”ParentElement\”, \”http://*.com/schema\”);Since normal messages are xmlDocuments, I’m pretty sure you can pass them directly where the C# program expects an xmlDocument object.
Eventually, you will probably develop several \”helper\” classes in C#,
so you will probably have something like an XmlHelpersClass, and it may have 5 to 20 methods in it that you can call.[/quote:9f69ecc8b3]First of all, [u:9f69ecc8b3]thanks a lot[/u:9f69ecc8b3] for your answer. I now understand how works your [i:9f69ecc8b3]C# Class[/i:9f69ecc8b3].
Actually, I need to insert a row (not blank) in my output flat file only if one of the values of the [color=orange:9f69ecc8b3][b:9f69ecc8b3]source schema[/b:9f69ecc8b3][/color:9f69ecc8b3] is [i:9f69ecc8b3]true[/i:9f69ecc8b3] else I don’t need to add it.
Doesn’t matter, I think I can use a part of your code and add it in a [color=green:9f69ecc8b3][b:9f69ecc8b3]Message assignement[/b:9f69ecc8b3] shape[/color:9f69ecc8b3] inside my [color=green:9f69ecc8b3][b:9f69ecc8b3]Construct Message[/b:9f69ecc8b3] shape[/color:9f69ecc8b3], juste after the [color=green:9f69ecc8b3][b:9f69ecc8b3]transform[/b:9f69ecc8b3] shape[/color:9f69ecc8b3] (where the mapping is done). [size=9:9f69ecc8b3][i:9f69ecc8b3]hope that is enough clear …[/i:9f69ecc8b3][/size:9f69ecc8b3]
But this involve I had to [color=darkred:9f69ecc8b3][b:9f69ecc8b3]promote[/b:9f69ecc8b3][/color:9f69ecc8b3] the value of my [color=orange:9f69ecc8b3][b:9f69ecc8b3]source schema[/b:9f69ecc8b3][/color:9f69ecc8b3] which is [i:9f69ecc8b3]true [/i:9f69ecc8b3]or [i:9f69ecc8b3]false [/i:9f69ecc8b3] to test if the row must be inserted or not, isn’t it ?
In any case, I’m gonna try this !
-
June 15, 2006 at 2:25 PM #13776
[quote:ef83a50512=\”nwalters\”]You can test a value in a schema three ways:
1) Promoted field: msgABC(namespace.fieldname)
2) Distinguished field: msgABC.fieldname
3) Use the Xpath function to query the value of the field – this is more complex, but sometimes handy:
strTempValue = xpath(msgABC,\”string(//*fieldname[1])\”).
The problem is that the namespace must often be added and the XPath can get very complex.[/quote:ef83a50512]
It works fine with XPath.
But I think there is simple way to insert a row: with a [color=orange:ef83a50512][b:ef83a50512]looping functoid[/b:ef83a50512][/color:ef83a50512].
Here is my [color=orange:ef83a50512][b:ef83a50512]source schema[/b:ef83a50512][/color:ef83a50512] (this is the result of my incoming flat file where TVA1 and TVA2 attributes are on [b:ef83a50512]1 line[/b:ef83a50512]):
[code:1:ef83a50512]<ns0:Record xmlns:ns0=\"http://TVASolution.sTVAin\">
<Transaction TVA1=\"19.6\" TVA2=\"0.0\"></Transaction>
</ns0:Record>[/code:1:ef83a50512]
But with a [color=orange:ef83a50512][b:ef83a50512]looping functoid[/b:ef83a50512][/color:ef83a50512], I obtained the following XML :
[code:1:ef83a50512]<ns0:rAgresso xmlns:ns0=\"http://TVASolution.sTVAout\">
<rTVA TVA=\"19.6\" />
<rTVA TVA=\"0.0\" />
</ns0:rAgresso>[/code:1:ef83a50512]
So as a result, I will have 2 rows in my output flat file, just as desired !Don’t you think this is less complex than adding C# code in the Orch. ?
-
-
-
-
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.