Coder Social home page Coder Social logo

Comments (4)

StabbyCutyou avatar StabbyCutyou commented on June 2, 2024

I'm running into this exact same problem.

I suspect the reason the error is not idempotent w/r/t which type isn't found, is because of how iterating maps in go is non-deterministic, and there is a lot of map iteration going on.

I think problem is here: https://github.com/droyo/go-xml/blob/master/xsd/parse.go#L148

The empty value of tns means that each time we don't find this, we set the key of "" to equal the latest schema root element we've iterated over, and so what happens is that you only get the last one under the "" key.

Then later when we go to resolve the global-list of types against the doc it thinks the namespace is for, it's only a matter of time before you hit something from one of the ones we parsed but accidentally rejected.

I've been attempting to hack around this to find a solution, and I've found something unique about each root that i can use instead of the namespace value we are trying to find, but that hasn't solved it yet, so I might still be missing something.

from go-xml.

StabbyCutyou avatar StabbyCutyou commented on June 2, 2024

ok, yea that solves it.

So, I don't think this is the best way to go about it, but if you alter the code in Parse, where it ranges over the schema object to do this:

		tns := root.Attr("", "targetNamespace")
		key := tns
		if key == "" {
			key = root.String()
		}

then have it set parsed[key] = s

then after pre-collecting types, the next range over schema, make a similar change:

		tns := root.Attr("", "targetNamespace")
		if tns == "" {
			tns = root.String()
		}
		s := parsed[tns]

That resolves it - assuming you don't have two documents that are completely identical. Also, this is definitely not very memory efficient but i'd wager that is less pressing than not being able to resolve types.

Unfortunately for me, I then run into this issue #117 lol

from go-xml.

droyo avatar droyo commented on June 2, 2024

That's pretty clever, using the whole document as an identifier. If you want to reduce the memory usage you could use a checksum of the document as a key.

Here's what the XSD spec has to say about empty target namespaces: https://www.w3.org/TR/xmlschema-0/#UndeclaredTNS

Element declarations from a schema with no target namespace validate unqualified elements in the instance document.

@StabbyCutyou , with the fix you proposed, what does the generated code look like? Does the XML document get used as a namespace? If so, I think the xsd and xsdgen packages would have to be changed to respect empty namespaces.

What's not clear to me from the spec, is how multiple schema with an empty target namespace should be handled. Should they be merged? What do more mature tools do?

I suspect what we'll end up doing is handling undeclared target namespace specially, and updating the command line tool to allow users to select a "primary" schema file. Currently you can only select a schema by namespace, which doesn't work when they don't have namespaces.

@johnnybubonic , regarding remote schema, see #35

from go-xml.

johnnybubonic avatar johnnybubonic commented on June 2, 2024

@droyo Thanks! Subscribed and will monitor there for possible fixes/merge in the future.

from go-xml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.