drmohundro / SWXMLHash

Simple XML parsing in Swift
MIT License
1.4k stars 203 forks source link

Module 'SWXMLHash' has no member named 'config #253

Closed imranrasheeddeveloper closed 2 years ago

imranrasheeddeveloper commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environment:

Additional context Add any other context about the problem here.

drmohundro commented 2 years ago

Hi @imranrasheeddeveloper - I'm not seeing the issue details actually filled out, it looks like it is still just using the template... the title suggests that you're seeing an issue related to 'SWXMLHash' has no member named 'config', though.

Do you have a repro set up somewhere that I could look at?

imranrasheeddeveloper commented 2 years ago

swift version 5 Xcode 12.4

Screenshot 2021-11-10 at 11 37 50 PM

fileprivate func parse() throws -> Group {
        let config = SWXMLHash.config { config in
            config.shouldProcessNamespaces = true
        }
        let parsedXml = config.parse(xmlString)

        var svgElement: SWXMLHash.XMLElement?
        for child in parsedXml.children {
            if let element = child.element {
                if element.name == "svg" {
                    svgElement = element
                    try prepareSvg(child.children)
                    break
                }
            }
        }
        let layout = svgElement != nil ? try parseViewBox(svgElement!) : nil
        try parseSvg(parsedXml.children)
        let root = layout != nil ? SVGCanvas(layout: layout!, contents: nodes) : Group(contents: nodes)
        if let opacity = svgElement?.attribute(by: "opacity") {
            root.opacity = getOpacity(opacity.text)
        }
        return root
    }
drmohundro commented 2 years ago

If you're using the latest version of SWXMLHash, the entry class has been renamed from SWXMLHash to XMLHash - see the release up at https://github.com/drmohundro/SWXMLHash/releases/tag/6.0.0.

This was done to fix a specific scenario mentioned in https://github.com/drmohundro/SWXMLHash/issues/242.

I think that might be the fix here. So, in your case, the code should instead look like:

    fileprivate func parse() throws -> Group {
        let config = XMLHash.config { config in
            config.shouldProcessNamespaces = true
        }
        let parsedXml = config.parse(xmlString)

        var svgElement: XMLHash.XMLElement?
        for child in parsedXml.children {
            if let element = child.element {
                if element.name == "svg" {
                    svgElement = element
                    try prepareSvg(child.children)
                    break
                }
            }
        }
        let layout = svgElement != nil ? try parseViewBox(svgElement!) : nil
        try parseSvg(parsedXml.children)
        let root = layout != nil ? SVGCanvas(layout: layout!, contents: nodes) : Group(contents: nodes)
        if let opacity = svgElement?.attribute(by: "opacity") {
            root.opacity = getOpacity(opacity.text)
        }
        return root
drmohundro commented 2 years ago

I'm closing the issue. If you're still having issues, please feel free to comment or re-open.