fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: XMLParser

XMLParser 6 months 5 days ago #6883

  Intexso's Avatar Topic Author Intexso Offline Posts: 67
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.

XMLParser 6 months 5 days ago #6884

  wriedmann's Avatar wriedmann Offline Posts: 1515
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

XMLParser 6 months 5 days ago #6885

  Chris's Avatar Chris Offline Posts: 1109
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

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

Last edit: by Chris.

XMLParser 6 months 5 days ago #6886

  Intexso's Avatar Topic Author Intexso Offline Posts: 67
Thanks (to both)!!!

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

XMLParser 6 months 4 days ago #6890

  lumberjack's Avatar lumberjack Offline Posts: 416
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.

  • Page:
  • 1