Home Page › Forums › BizTalk 2004 – BizTalk 2010 › DTD removal and string replacement
- This topic has 0 replies, 1 voice, and was last updated 6 years, 10 months ago by
community-content.
-
AuthorPosts
-
-
May 16, 2006 at 3:49 PM #13615
I want to strip a DTD declaration in an XML instance in the Receive pipeline component and add some schema declarations to the root node –
From –
[color=indigo:e6d3c3f283][code:1:e6d3c3f283]<!DOCTYPE ONIXmessage SYSTEM \"http://www.editeur.org/onix/2.0/short/onix-international.dtd\">
<ONIXmessage>To –
<ONIXmessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=”http://CompanyName.ProjectName.Schemas\">[/code:1:e6d3c3f283][/color:e6d3c3f283]
I could do it like this[size=9:e6d3c3f283][color=darkblue:e6d3c3f283][code:1:e6d3c3f283]public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
{
IBaseMessagePart bodyPart = inmsg.BodyPart;
if (bodyPart!=null)
{
Stream originalStrm = bodyPart.Data;
originalStrm = bodyPart.GetOriginalDataStream();
byte[] buffer = new byte[originalStrm.Length];
originalStrm.Read(buffer,0,Convert.ToInt32(originalStrm.Length));
string xmlString = Encoding.UTF8.GetString(buffer);
// Do replace here
Stream strm = new MemoryStream(ConvertToBytes(xmlString));
bodyPart.Data = strm;
pc.ResourceTracker.AddResource( strm );
}
return inmsg;
}[/code:1:e6d3c3f283][/color:e6d3c3f283][/size:e6d3c3f283]
But I dont want to read the full message into a string as the message could be in 100s of MBs.The ideal would be either to do a replace on a stream (not possible in .NET in my knowledge) or read in the first 1000 chars in which the DTD surely resides
[code:1:e6d3c3f283]string contents = originalStrm.Read(buffer,0, 1000); [color=olive]//the part I need to replace will be present in the first 1000 chars[/color].[/code:1:e6d3c3f283]
But then how to prepend this stream before the rest of the stream into the memorystream which gets assigned to the bodyPart.Data?
[color=darkblue:e6d3c3f283][code:1:e6d3c3f283]
object originalFileNameObj = inmsg.Context.Read(\"ReceivedFileName\",@\"http://schemas.microsoft.com/BizTalk/2003/file-properties\");
string strReceivedFileName;
if (originalFileNameObj != null)
{
strReceivedFileName = Path.GetFileName(originalFileNameObj.ToString());
StreamWriter sw = File.CreateText(strReceivedFileName);
sw.Write(contents);
sw.Close();
}[/code:1:e6d3c3f283]
[/color:e6d3c3f283]
Cant concatenate streams in .NET either (to my knowledge).Only dirty solution left is to resave the file with a StreamWriter
[color=darkblue:e6d3c3f283][code:1:e6d3c3f283]object originalFileNameObj = inmsg.Context.Read(\"ReceivedFileName\",@\"http://schemas.microsoft.com/BizTalk/2003/file-properties\");
string strReceivedFileName;
if (originalFileNameObj != null)
{
strReceivedFileName = Path.GetFileName(originalFileNameObj.ToString());
StreamWriter sw = File.CreateText(strReceivedFileName);
sw.Write(contents);
sw.Close();[/code:1:e6d3c3f283]}[/color:e6d3c3f283]
The problem with this is – I have to read in the full message into a string and I may not have write permissions on the FTP directory where this is received.Also – I cannot use a Streaming XPath reader because of this reason
http://www.thescripts.com/forum/thread176011.html
(somehow on hitting an ONIXMessage DTD, the .NET XmlReader breaks)Anyone have any better ideas than I do?
thanks in advance!
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.