Using XML

This forum is meant for questions and discussions about the X# language and tools
Post Reply
JacentyK
Posts: 2
Joined: Tue Sep 19, 2023 1:26 pm
Location: Polska

Using XML

Post by JacentyK »

Hi, I'm testing the X# language and system.
I want to use it to communicate with KSeF (e-invoices in Poland). I try to test service XML, and I wrote code:

Code: Select all

USING System
USING System.Xml          
USING System.Xml.XmlNode


FUNCTION TestXML
	LOCAL oXmlDocument AS System.Xml.XmlNode
	LOCAL strXML AS STRING                  
	
	oXmlDocument := System.Xml.XmlNode()

	RETURN strXML
I get a compiler error:
error XS0234: The type or namespace name 'XmlNode' does not exist in the namespace 'System.Xml' (are you missing an assembly reference?)
This error is to line:

Code: Select all

USING System.Xml.XmlNode
How I can use all standards classes or .Net functions and classes .Net in my application?
For example: XMLDom, XML, HTPRequest and other?

Regards
Jacek
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Using XML

Post by Chris »

Hi Jacek,

You need to add a reference to the System.Xml library (dll), which contains the xml classes. If you do not know how to do that, please tell us which IDE you are using and will send some instructions.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Luc
Posts: 28
Joined: Sat Apr 30, 2016 7:31 pm
Location: Belgium

Re: Using XML

Post by Luc »

Hi Jacek,

when KsEF is according to the UBL/Peppol rules it will be very hard to create the xml yourself and also not the best way to do.

I propose you use the .net library ubllarsen (see https://github.com/UblSharp/UblSharp)

It offers an object model to ubl and will create the xml for you using serialization. Included are also a lot of samples.
Understanding the ubl requirements is already complicated enough and it will help you to code while using syntax code completion.


small sample:

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
USING ublSharp
USING UblSharp.CommonAggregateComponents
USING UblSharp.CommonExtensionComponents
USING UblSharp.UnqualifiedDataTypes
USING UblSharp.XmlDigitalSignature

USING System.IO
USING System.Xml
USING System.Xml.Serialization

***

SELF:w_oUBLInvoice := ublSharp.InvoiceType{}
SELF:Create(oExternalInvoice, oCustomer, oSupplier, aInvoiceEntries)
self:SaveInvoiceXML(sFullName)

PROTECT METHOD SaveInvoiceXML(sFullName AS STRING) AS LONG PASCAL CLASS fExportUBLbase
LOCAL oSetting AS XmlWriterSettings
LOCAL oXMLWriter AS xmlWriter
LOCAL hResult AS LONG


TRY
oSetting := XmlWriterSettings{}
oSetting:Indent := TRUE

oSetting:IndentChars := space(4)


oSetting:NewLineOnAttributes := FALSE


oXmlWriter := xmlWriter:Create(sFullName, oSetting)

LOCAL oXMLSerializer AS System.Xml.Serialization.XmlSerializer
oXMLSerializer := System.Xml.Serialization.XmlSerializer{ SELF:w_oUBLInvoice:GetType() }
oXMLSerializer:Serialize(oXMLWriter, SELF:w_oUBLInvoice)

CATCH e AS exception
hresult := e:HResult
THROW

FINALLY
IF oXmlWriter != NULL
oXMLWriter:Close()
ENDIF

END TRY

RETURN hresult


HIDDEN METHOD Create(oExternalInvoice AS dInvoice, oCustomer AS dCustomer, oSupplier AS dCustomer, aInvoiceEntries AS ARRAY)

AS LONG PASCAL CLASS fExportUBLAccountancy
LOCAL hResult AS LONG

TRY

SELF:w_oUBLInvoice:UBLVersionID := "2.1"
SELF:w_oUBLInvoice:CustomizationID := "urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0"
SELF:w_oUBLInvoice:ProfileID := "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"


LOCAL sOrderNumber, sorderRef AS STRING
sOrderNumber := oExternalInvoice:BES_NUMMER
sOrderNumber := sOrderNumber:Trim()

sOrderRef := oExternalinvoice:REF_KLANT
sOrderRef := sOrderRef:Trim()

IF sOrderNumber:Length > 0
VAR oOrderReference := OrderReferenceType{}
oOrderReference:ID := SELF:CreateIdentifier(sOrderNumber)
oOrderReference:SalesOrderID := SELF:CreateIdentifier(sOrderNumber)
IF sOrderRef:Length > 0
oOrderReference:CustomerReference := sOrderRef
ENDIF

SELF:w_oublInvoice:OrderReference := oOrderReference


SELF:w_oUBLInvoice:BuyerReference := sOrderNumber
//Error message: A buyer reference or purchase order reference MUST be provided.
ENDIF


SELF:w_oUBLInvoice:ID := SELF:CreateIdentifier(oExternalInvoice:FAKT_NR:tostring() )

....


PROTECT METHOD CreateIdentifier(sID AS STRING) AS IdentifierType PASCAL CLASS fexportUBLbase

VAR oIdentifier := IdentifierType{}
oIdentifier:Value := sID:Trim()

RETURN oIdentifier


Regards,

Luc
Post Reply