public static void Main(string[] args) { if (args.Length != 1) { Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); Environment.Exit(1); } // read and parse message from file try { var parser = new PipeParser(); var messageFile = new FileInfo(args[0]); var fileLength = SupportClass.FileLength(messageFile); var r = new StreamReader(messageFile.FullName, Encoding.Default); var cbuf = new char[(int)fileLength]; Console.Out.WriteLine( $"Reading message file ... {r.Read((char[])cbuf, 0, cbuf.Length)} of {fileLength} chars"); r.Close(); var messString = Convert.ToString(cbuf); var mess = parser.Parse(messString); Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); XMLParser xp = new AnonymousClassXMLParser(); // loop through segment children of message, encode, print to console var structNames = mess.Names; for (var i = 0; i < structNames.Length; i++) { var reps = mess.GetAll(structNames[i]); for (var j = 0; j < reps.Length; j++) { if (reps[j] is ISegment) { // ignore groups var docBuilder = new XmlDocument(); var doc = new XmlDocument(); // new doc for each segment var root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.Encode((ISegment)reps[j], root); var out_Renamed = new StringWriter(); Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); var segmentConstructTypes = new Type[] { typeof(IMessage) }; var segmentConstructArgs = new object[] { null }; var s = (ISegment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.Parse(s, root); var doc2 = new XmlDocument(); var root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.Encode(s, root2); var out2 = new StringWriter(); var ser = XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { Console.Out.WriteLine("Re-encode OK"); } else { Console.Out.WriteLine( $"Warning: XML different after parse and re-encode: {Environment.NewLine}{out2}"); } } } } } catch (Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
public static void Main(System.String[] args) { if (args.Length != 1) { System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); System.Environment.Exit(1); } //read and parse message from file try { PipeParser parser = new PipeParser(); System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default); char[] cbuf = new char[(int)fileLength]; //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'" System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); System.String messString = System.Convert.ToString(cbuf); Message mess = parser.parse(messString); System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); ca.uhn.hl7v2.parser.XMLParser xp = new AnonymousClassXMLParser(); //loop through segment children of message, encode, print to console System.String[] structNames = mess.Names; for (int i = 0; i < structNames.Length; i++) { Structure[] reps = mess.getAll(structNames[i]); for (int j = 0; j < reps.Length; j++) { if (typeof(Segment).IsAssignableFrom(reps[j].GetType())) { //ignore groups //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" //UPGRADE_ISSUE: Method 'javax.xml.parsers.DocumentBuilderFactory.newInstance' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersDocumentBuilderFactory'" //DocumentBuilderFactory.newInstance(); System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument(); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.encode((Segment)reps[j], root); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); System.Type[] segmentConstructTypes = new System.Type[] { typeof(Message) }; System.Object[] segmentConstructArgs = new System.Object[] { null }; Segment s = (Segment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.parse(s, root); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument(); System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.encode(s, root2); System.IO.StringWriter out2 = new System.IO.StringWriter(); System.Xml.XmlTextWriter ser = new System.Xml.XmlTextWriter(out2); //System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { System.Console.Out.WriteLine("Re-encode OK"); } else { System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString()); } } } } } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
public static void Main(System.String[] args) { if (args.Length != 1) { System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); System.Environment.Exit(1); } //read and parse message from file try { PipeParser parser = new PipeParser(); System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default); char[] cbuf = new char[(int) fileLength]; //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'" System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[]) cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); System.String messString = System.Convert.ToString(cbuf); Message mess = parser.parse(messString); System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); ca.uhn.hl7v2.parser.XMLParser xp = new AnonymousClassXMLParser(); //loop through segment children of message, encode, print to console System.String[] structNames = mess.Names; for (int i = 0; i < structNames.Length; i++) { Structure[] reps = mess.getAll(structNames[i]); for (int j = 0; j < reps.Length; j++) { if (typeof(Segment).IsAssignableFrom(reps[j].GetType())) { //ignore groups //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" //UPGRADE_ISSUE: Method 'javax.xml.parsers.DocumentBuilderFactory.newInstance' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersDocumentBuilderFactory'" //DocumentBuilderFactory.newInstance(); System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument(); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.encode((Segment) reps[j], root); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); System.Type[] segmentConstructTypes = new System.Type[]{typeof(Message)}; System.Object[] segmentConstructArgs = new System.Object[]{null}; Segment s = (Segment) reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.parse(s, root); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument(); System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.encode(s, root2); System.IO.StringWriter out2 = new System.IO.StringWriter(); System.Xml.XmlTextWriter ser = new System.Xml.XmlTextWriter(out2); //System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { System.Console.Out.WriteLine("Re-encode OK"); } else { System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString()); } } } } } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
public static void Main(System.String[] args) { if (args.Length != 1) { System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); System.Environment.Exit(1); } //read and parse message from file try { PipeParser parser = new PipeParser(); System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); System.IO.StreamReader r = new System.IO.StreamReader( messageFile.FullName, System.Text.Encoding.Default); char[] cbuf = new char[(int)fileLength]; System.Console.Out.WriteLine( "Reading message file ... " + r.Read(cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); System.String messString = System.Convert.ToString(cbuf); IMessage mess = parser.Parse(messString); System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); NHapi.Base.Parser.XMLParser xp = new AnonymousClassXMLParser(); //loop through segment children of message, encode, print to console System.String[] structNames = mess.Names; for (int i = 0; i < structNames.Length; i++) { IStructure[] reps = mess.GetAll(structNames[i]); for (int j = 0; j < reps.Length; j++) { if (typeof(ISegment).IsAssignableFrom(reps[j].GetType())) { //ignore groups System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.Encode((ISegment)reps[j], root); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); System.Console.Out.WriteLine( "Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); System.Type[] segmentConstructTypes = { typeof(IMessage) }; System.Object[] segmentConstructArgs = { null }; ISegment s = (ISegment) reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.Parse(s, root); System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument(); System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.Encode(s, root2); System.IO.StringWriter out2 = new System.IO.StringWriter(); System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { System.Console.Out.WriteLine("Re-encode OK"); } else { System.Console.Out.WriteLine( "Warning: XML different after parse and re-encode: \r\n" + out2); } } } } } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
public static void Main(String[] args) { if (args.Length != 1) { Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); Environment.Exit(1); } //read and parse message from file try { PipeParser parser = new PipeParser(); FileInfo messageFile = new FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); StreamReader r = new StreamReader(messageFile.FullName, Encoding.Default); char[] cbuf = new char[(int) fileLength]; Console.Out.WriteLine("Reading message file ... " + r.Read((Char[]) cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); String messString = Convert.ToString(cbuf); IMessage mess = parser.Parse(messString); Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); XMLParser xp = new AnonymousClassXMLParser(); //loop through segment children of message, encode, print to console String[] structNames = mess.Names; for (int i = 0; i < structNames.Length; i++) { IStructure[] reps = mess.GetAll(structNames[i]); for (int j = 0; j < reps.Length; j++) { if (typeof (ISegment).IsAssignableFrom(reps[j].GetType())) { //ignore groups XmlDocument docBuilder = new XmlDocument(); XmlDocument doc = new XmlDocument(); //new doc for each segment XmlElement root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.Encode((ISegment) reps[j], root); StringWriter out_Renamed = new StringWriter(); Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); Type[] segmentConstructTypes = new Type[] {typeof (IMessage)}; Object[] segmentConstructArgs = new Object[] {null}; ISegment s = (ISegment) reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.Parse(s, root); XmlDocument doc2 = new XmlDocument(); XmlElement root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.Encode(s, root2); StringWriter out2 = new StringWriter(); XmlWriter ser = XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { Console.Out.WriteLine("Re-encode OK"); } else { Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString()); } } } } } catch (Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }