C# .NET Core 6: Get rootname, namespace or DTD using xmlreader
using (var stream = new MemoryStream())
{
FormFile?.CopyTo(stream);
stream.Seek(0, SeekOrigin.Begin);
var settings = new XmlReaderSettings()
{
// Parse file but do not reolve
DtdProcessing = DtdProcessing.Parse,
XmlResolver = null
};
using (var reader = XmlReader.Create(stream, settings))
{
var done = false;
while (reader.Read() && !done)
{
// something weird happened, bail out
//if (reader.EOF)
// return;
switch (reader.NodeType)
{
// Assume cXML
case XmlNodeType.DocumentType:
DocumentType = reader.GetAttribute("SYSTEM") + "";
break;
case XmlNodeType.Element:
switch (reader.LocalName)
{
// Assume an UBL dpcument of some kind
case "CustomizationID":
reader.Read();
SetCustomization(reader.Value);
break;
// Only OIOUBL, done and exit
case "UBLlVersionID":
reader.Read();
UblVersion = reader.Value;
done = true;
break;
// Only OIOXML, done and exit
case "TypeCode":
reader.Read();
TypeCode = reader.Value;
done = true;
break;
default:
if (string.IsNullOrEmpty(RootName))
{
RootName = reader.Name;
SetNamespace(reader.NamespaceURI);
}
break;
}
break;
}
}
reader.Close();
}
}
23. July 2023
plykkegaard
An utility to retrieve current year
This is a procedure to use in Seeburger BIC Mapping Designer
/* -----------------------------
Peter Lykkegaard, 25 apr 2023
-----------------------------
procedure getUUID
Parameters:
None
Output
String
Get ramdom UUID
----------------------------- */
#importJavaStart
import java.util.UUID;
#importJavaEnd
local
lvOutput$;
#javastart
_StrVar_LVOUTPUT.setString(UUID.randomUUID().toString());
#javaend
exitProc(lvOutput$);
An utility to decode or unescape HTML characters in XML (EDI) documents
This is a procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling
/* -----------------------------
Peter Lykkegaard, 25 apr 2023
-----------------------------
procedure unescapeHTML
Parameters:
Source / String, alphanumeric
Output
String, alphanumericString
Adapted from How to Unescape HTML in Java using Plain Java
https://howtodoinjava.com/java/string/unescape-html-to-string/
----------------------------- */
local lvOutput$;
#importJavaStart
import java.util.HashMap;
#importJavaEnd
// Save source in case changes are not needed
copy pSource$ to lvOutput$;
// Check for any ampersand / & character
if (containsSubstring(pSource$, "&") != 0)
if (containsSubstring(pSource$, "&") != 0)
// HTML decode ampersand / &
copy replaceAll(pSource$, "&", "&") to pSource$;
endif
#javastart
int i, j;
boolean continueLoop;
int skip = 0;
HashMap<String, String> htmlEntities = new HashMap<String, String>();
htmlEntities.put("<", "<");
htmlEntities.put(">", ">");
htmlEntities.put("&", "&");
htmlEntities.put(""", "\"");
htmlEntities.put(" ", " ");
htmlEntities.put("©", "\u00a9");
htmlEntities.put("®", "\u00ae");
htmlEntities.put("€", "\u20a0");
htmlEntities.put("Å", "Å");
htmlEntities.put("Æ", "Æ");
htmlEntities.put("Ø", "Ø");
htmlEntities.put("å", "å");
htmlEntities.put("æ", "æ");
htmlEntities.put("ø", "ø");
String source = _StrVar_PSOURCE.getString();
do {
continueLoop = false;
i = source.indexOf("&", skip);
if (i > -1) {
j = source.indexOf(";", i);
if (j > i) {
String entityToLookFor = source.substring(i, j + 1);
String value = (String) htmlEntities.get(entityToLookFor);
if (value != null) {
source = source.substring(0, i) + value + source.substring(j + 1);
continueLoop = true;
} else if (value == null) {
skip = i + 1;
continueLoop = true;
}
}
}
} while (continueLoop);
_StrVar_LVOUTPUT.setString(source);
#javaend
endif
exitProc(lvOutput$);
An utility to format current datetime as a UTC string according to RFC 3339
A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling
// -----------------------------
// Peter Lykkegaard, 12 okt 2022
// -----------------------------
// procedure getCurrentDateTimeUTC
// Parameters: None
// Get current date / time
// Format as String in UTC RFC 3339 format (eg 2022-10-13T23:37:18+02:00)
// Output
// alphanumeric / String
// Ref: https://medium.easyread.co/understanding-about-rfc-3339-for-datetime-formatting-in-software-engineering-940aa5d5f68a
#importJavaStart
import java.time.format.DateTimeFormatter;
import java.time.OffsetDateTime;
#importJavaEnd
local output$;
#javaStart
String output;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
OffsetDateTime now = OffsetDateTime.now();
output = dtf.format(now);
_StrVar_OUTPUT.setString(output);
#javaEnd
exitProc(output$);