lestrrat-go / libxml2

Interface to libxml2, with DOM interface
MIT License
230 stars 55 forks source link

Incorrect element name when creating element using `CreateElementNS` without namespace prefix #104

Closed guitarpawat closed 3 months ago

guitarpawat commented 4 months ago

Describe the bug

When creating new elements using function CreateElementNS without a namespace prefix, it creates a new node with an incorrect name.

To Reproduce / Expected behavior

package main

import (
    "fmt"
    "github.com/lestrrat-go/libxml2/dom"
)

func main() {
    root := dom.CreateDocument()
    doc, err := root.CreateElementNS("https://example.com", "Document")
    if err != nil {
        fmt.Println("err:", err)
        return
    }
    _ = root.SetDocumentElement(doc)
    test, _ := root.CreateElementNS("https://example.com", "A")
    _ = doc.AddChild(test)
    fmt.Println(root.Dump(true))
}

Output:

<?xml version="1.0" encoding="utf-8"?>
<Documen: xmlns:Documen="https://example.com">
  <: xmlns:="https://example.com"/>
</Documen:>

There are two possible solutions

  1. Return an error if there is no namespace prefix.
  2. Create an element using the default namespace.
github-actions[bot] commented 3 months ago

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 months ago

This issue was closed because it has been stalled for 7 days with no activity. This does not mean your issue is rejected, but rather it is done to hide it from the view of the maintains for the time being. Feel free to reopen if you have new comments