fbpx

XMLParser

More
2 months 1 day ago #1 by Eric Boomsma
XMLParser was created by Eric Boomsma
Hello,

A long time ago I got a class named XMLParser from someone. Unfortunately I have not documented the source.

With this class I can easily build, store and read XML files. I have the source code for this class (in VO).
In this class much of the type PTR is used and I also see a lot of casts. Several functions now expect PSZ in Vulcan (and X #) and that is why I think the code needs to be rewritten properly.

Does anyone know if an XMLParser class is available somewhere (or maybe an assembly exists) that can be used to build, store and read XML files?

Thank is advance for your answer.

Eric

Please Log in or Create an account to join the conversation.

More
2 months 1 day ago #2 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic XMLParser
Hi Eric,

you can use the XML parser classes in the .NET Framework: XmlNode and XmlDocument in the System.XML namespace. I would not use VO classes if possible (I have done the inverse thing: I'm using the .NET classes in my VO application through a COM DLL).
docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument

Wolfgang

Please Log in or Create an account to join the conversation.

More
2 months 1 day ago - 2 months 1 day ago #3 by Chris Pyrgas
Replied by Chris Pyrgas on topic XMLParser
Yeah, please check the documentation about System.Xml namespace, System.Xml.XmlDocument etc. You only need to add a reference to System.Xml library to use them

docs.microsoft.com/en-us/dotnet/api/syst...w=netframework-4.7.1

docs.microsoft.com/en-us/dotnet/api/syst...w=netframework-4.7.1

Edit: I am way slower than Wolfgang :)

XSharp Development Team
chris(at)xsharp.eu
Last edit: 2 months 1 day ago by Chris Pyrgas.

Please Log in or Create an account to join the conversation.

More
2 months 1 day ago #4 by Eric Boomsma
Replied by Eric Boomsma on topic XMLParser
Thanks (to both)!!!

Please Log in or Create an account to join the conversation.

More
2 months 9 hours ago #5 by Johan Nel
Replied by Johan Nel on topic XMLParser
Hi Eric,

Intexso wrote: Does anyone know if an XMLParser class is available somewhere (or maybe an assembly exists) that can be used to build, store and read XML files?

Here is a reader and writer for Xml. Methods from my IniFile to convert Ini files to Xml format. Should get you going.
METHOD ReadXml() AS VOID
	LOCAL sFileXml AS STRING
	LOCAL xr AS XmlReader
	LOCAL settings AS XmlReaderSettings
	LOCAL s, n, v AS STRING
	sFileXml := SELF:sFile:Replace(Path.GetExtension(SELF:sFile), ".config")
	IF !File.Exists(sFileXml)
		RETURN
	ENDIF
	settings := XmlReaderSettings{}
	settings:IgnoreWhitespace := TRUE
	xr := XmlReader.Create(sFileXml, settings)
	xr:MoveToContent()
	IF xr:Name == "configuration"
		WHILE xr:Read()
			IF xr:NodeType = XmlNodeType.EndElement
				LOOP
			ENDIF
			IF xr:Name == "section"
				s := xr["name"]
			ELSEIF xr:Name == "entry"
				n := xr["name"]
				v := xr["value"]
				SELF:SetString(s, n, v)
			ENDIF
		ENDDO
	ENDIF
	xr:Close()
RETURN

METHOD FlushXml() AS VOID
	LOCAL sFileXml AS STRING
	LOCAL xw AS XmlTextWriter
	LOCAL s, n, v AS STRING
	LOCAL sSections, sItems AS STRING[]
	LOCAL i, j AS INT
	sFileXml := SELF:sFile:Replace(Path.GetExtension(SELF:sFile), ".config")
	IF File.Exists(sFileXml)
		File.Copy(sFileXml, sFileXml + ".bak", TRUE)
	ENDIF
	xw := XmlTextWriter{sFileXml, Encoding.UTF8}
	xw:Formatting := Formatting.Indented
	xw:WriteStartDocument()
	xw:WriteStartElement("configuration")
	sSections := SELF:GetSectionNames()
	FOR i := 0 UPTO sSections:Length - 1
		s := sSections[i]
		xw:WriteStartElement("section")
		xw:WriteAttributeString("name", s)
		sItems := SELF:GetItemNames(s)
		FOR j := 0 UPTO sItems:Length - 1
			n := sItems[j]
			v := SELF:GetString(s, n)
			xw:WriteStartElement("entry")
			xw:WriteAttributeString("name", n)
			xw:WriteAttributeString("value", v)
			xw:WriteEndElement()
		NEXT
		xw:WriteEndElement()
	NEXT
	xw:WriteEndDocument()
	xw:Close()
RETURN
HTH,

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.