Skip to content

Return Unrecognized Elements as a String? #104

@eyallen

Description

@eyallen

I am trying to implement a parser for a XML format that can contain extensions. These extensions are valid XML, but we don't know what format they will be in.

I'd like to return any unrecognized elements as a string for later parsing by consumers. Is this possible?

An example:

<Data version="2.0">
  <Sample>Testing</Sample>
  <Extensions>
   // This could be anything
  </Extensions>
</Data>

I'd like the following structure:

struct Data: Codable {
  let version: String
  let extensions: String?
}

It seems that since Extensions is valid XML, it always gets parsed and thus I am unable to convert this back to a string.

I was hoping to be able to do this via an init(from: decoder: Decoder) but at that point it appears it is already to late.

Any ideas?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions