Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespaces are not supported #2

Open
awalterschulze opened this issue Dec 29, 2016 · 0 comments
Open

namespaces are not supported #2

awalterschulze opened this issue Dec 29, 2016 · 0 comments

Comments

@awalterschulze
Copy link
Member

awalterschulze commented Dec 29, 2016

Adding namespaces has three problems.

  1. Currently the xml parser does not return the namespaces. This can be fixed with this diff
diff --git a/parser/xml/parser.go b/parser/xml/parser.go
index d63e9bb..4e40e18 100644
--- a/parser/xml/parser.go
+++ b/parser/xml/parser.go
@@ -196,14 +196,21 @@ func (p *xmlParser) Bool() (bool, error) {

 func (p *xmlParser) String() (string, error) {
        if p.tok == nil && p.attrIndex < len(p.attrs) {
+               a := p.attrs[p.attrIndex]
                if p.attrValue {
-                       return p.textPrefix + p.attrs[p.attrIndex].Value, nil
+                       return p.textPrefix + a.Value, nil
                } else {
-                       return p.attrPrefix + p.attrs[p.attrIndex].Name.Local, nil
+                       if len(a.Name.Space) == 0 {
+                               return p.attrPrefix + a.Name.Local, nil
+                       }
+                       return p.attrPrefix + a.Name.Space + ":" + a.Name.Local, nil
                }
        }
        if s, ok := p.tok.(StartElement); ok {
-               return p.elemPrefix + s.Name.Local, nil
+               if len(s.Name.Space) == 0 {
+                       return p.elemPrefix + s.Name.Local, nil
+               }
+               return p.elemPrefix + s.Name.Space + ":" + s.Name.Local, nil
        }
        if c, ok := p.tok.(CharData); ok {
                return p.textPrefix + string(c), nil

This is so easy because the golang xml parsing library already resolves the namespaces for us. Probably with a preparse phase, which is technically some sort of cheating, because now we don't need to keep any state in the validator, this state is kept in the parser for us by the golang xml parser.

  1. nsName in relaxNG only matches the namespace and not the element name, so in this case relapse will need to be able match prefixes on names. The hardest part about this would be to design the syntax and thinking about whether names should allow all types of functions and not just a very constrained subset.

  2. Also xmlns attributes would need to be matched which is currently conveniently done as an optional attribute with any value. When namespaces are returned by the parser their name will also require a more complex and specific pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant