mlabs-haskell / opc-xml-da-client

OPC XML-DA Client for Haskell
MIT License
2 stars 1 forks source link

Xml parse error with empty element of type xsd:string #17

Closed olafklinke closed 2 years ago

olafklinke commented 2 years ago

The following should return the empty text but fails.

{-# LANGUAGE OverloadedStrings #-}
import OpcXmlDaClient.Protocol.XmlParsing
import XmlParser
import Data.ByteString (ByteString)
import Data.Text (Text)
emptyString = "<Value xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\"></Value>" :: ByteString
parseByteString value emptyString -- fails with "no nodes left"

The reason is that for xsd:string the definition of value is essentially this:

textElt = children $ contentNode textContent :: Element Text

but emptyString has no children. Insert any text in the Value tag and the parser succeeds.

blamario commented 2 years ago

I don't see anything wrong with this behaviour as far as XML goes, but I'm not familiar with the OPC spec. Can you point to the section of the spec that explains this?

olafklinke commented 2 years ago

The OPC spec has nothing to do with this. Attached is part of a BrowseResponse from an OPC server which is not parsed by opc-xml-da-client because a Value element with type annotation xsd:string (thus a general xml string type) and no content is not parsed.

<Properties
                        xsi:type="ns1:ItemProperty"
                        Description="Item value"
                        ItemName="Alias"
                        Name="ns1:value"
                        ItemPath="Loc/Wec/Plant1/">
                        <Value
                            xsi:type="xsd:string">
                            </Value>
</Properties>
olafklinke commented 2 years ago

This is linked to an issue in xml-parser which when resolved can help implement a fix.

nikita-volkov commented 2 years ago

I'll address it in xml-parser

nikita-volkov commented 2 years ago

It's been addressed in xml-parser-0.1.1.

olafklinke commented 2 years ago

The issue seems to be fixed in xml-parser-0.1.1. Please update the cabal file to use xml-parser >= 0.1.1, then test my above code. If that does not throw an error, please increase this package's version number and close the issue.

nikita-volkov commented 2 years ago

@blamario Can you do this?

blamario commented 2 years ago

Yes, just not right now.

blamario commented 2 years ago

Who's the client, where do I Harvest this?

nikita-volkov commented 2 years ago

The client is Westfalen Wind.

The presented code is already tested here: https://github.com/nikita-volkov/xml-parser/commit/fffb206d2d59bdf3340e609e8f5db0efaa2f8e5c. So it seems like all we need is a version bump. And I'm pushing it now.

olafklinke commented 2 years ago

Please also bump the version of opc-xml-da-client so that downstream packages can make sure that this fixed xml-parser is used.

nikita-volkov commented 2 years ago

@olafklinke I'm lacking rights to upload to Hackage. Can you add me? My username is NikitaVolkov there