GithubHelp home page GithubHelp logo

dvreeze / yaidom Goto Github PK

View Code? Open in Web Editor NEW
26.0 26.0 3.0 5.57 MB

Yet another immutable XML DOM-like API

License: Apache License 2.0

Scala 99.45% HTML 0.11% XSLT 0.02% CSS 0.42%
query-api scala xml

yaidom's People

Contributors

dvreeze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yaidom's Issues

yaidom-0003 Bug in method Scope.includingNamespace

Method Scope.includingNamespace returns the Scope itself if the namespace is the "xml" namespace or if prefixesForNamespace(namespaceUri).contains(namespaceUri)). The latter is of course incorrect. It should be: !prefixesForNamespace(namespaceUri).isEmpty. It is likely that the bug is not encountered, but it is still a bug.

yaidom-0004 removeAllInterElementWhitespace doesn't work when some of the children are comments

When using the following XML in a scala worksheet

import java.io.ByteArrayInputStream

import eu.cdevreeze.yaidom.parse.DocumentParserUsingSax

val xml = """<?xml version="1.0" encoding="UTF-8"?>
<rootElem>
  <listing>
    <item />
    <item />
    <!-- some comment -->
  </listing>
</rootElem>
"""

val inputStream = new ByteArrayInputStream(xml.getBytes)
val parser = DocumentParserUsingSax.newInstance()
val requestDoc = parser.parse(inputStream)
val documentElementWithoutWhitespace = requestDoc.documentElement.removeAllInterElementWhitespace

The content of elemsWithoutWhitespace still contains text nodes with white-space only around the item elements. The white-space around listing is removed correctly.

As shown by this textual representation:

before whitespace removal:

documentElementWithWhitespace: eu.cdevreeze.yaidom.simple.Elem = elem(
  qname = QName("rootElem"),
  children = Vector(
    text("""
  """),
    elem(
      qname = QName("listing"),
      children = Vector(
        text("""
    """),
        elem(
          qname = QName("item")
        ),
        text("""
    """),
        elem(
          qname = QName("item")
        ),
        text("""
    """),
        comment(""" some comment """),
        text("""
  """)
      )
    ),
    text("""
""")
  )
)

after (incorrect) white-space removal

documentElementWithoutWhitespace: eu.cdevreeze.yaidom.simple.Elem = elem(
  qname = QName("rootElem"),
  children = Vector(
    elem(
      qname = QName("listing"),
      children = Vector(
        text("""
    """),
        elem(
          qname = QName("item")
        ),
        text("""
    """),
        elem(
          qname = QName("item")
        ),
        text("""
    """),
        comment(""" some comment """),
        text("""
  """)
      )
    )
  )
)

running the same code, without the comment results in the expected output

import java.io.ByteArrayInputStream

import eu.cdevreeze.yaidom.parse.DocumentParserUsingSax

val xml = """<?xml version="1.0" encoding="UTF-8"?>
<rootElem>
  <listing>
    <item />
    <item />
  </listing>
</rootElem>
"""

val inputStream = new ByteArrayInputStream(xml.getBytes)
val parser = DocumentParserUsingSax.newInstance()
val requestDoc = parser.parse(inputStream)
val documentElementWithoutWhitespace = requestDoc.documentElement.removeAllInterElementWhitespace

results in what would be expected in the first example

documentElementWithoutWhitespace: eu.cdevreeze.yaidom.simple.Elem = elem(
  qname = QName("rootElem"),
  children = Vector(
    elem(
      qname = QName("listing"),
      children = Vector(
        elem(
          qname = QName("item")
        ),
        elem(
          qname = QName("item")
        )
      )
    )
  )
)

yaidom-0001 Elem.toTreeRepr inefficient

Method Elem.toTreeRepr (and therefore Elem.toString) takes far too much memory. In a REPL session, when parsing/creating a very large Document, the (implicit) call of method toString easily leads to an OutOfMemoryError.

yaidom-0002 DocumentPrinterUsingSax potentially not emitting namespace declarations

This is a bug related to the use of DocumentPrinterUsingSax. Trait YaidomToSaxEventsConversions (used in DocumentPrinterUsingSax) does not treat namespace declarations as attributes. That is correct, and method startPrefixMapping should add namespace declarations. On the other hand, it used to be the case that the attributes passed to method startElement included namespace declarations as well. Though strictly incorrect, the old behaviour was more reliable in emitting namespace declarations.

This must be investigated further, and hopefully an elegant solution can be found. The old behaviour can be found in class DocumentPrinterUsingSax as it was before 2015-05-27.

Artifacts for Scala 2.11

Please publish artifacts built for Scala 2.11 final. We sorely lack an updated alternative to scala-xml :)

yaidom-0005 Path.toCanonicalXPath broken for default namespace

See the following code:

import eu.cdevreeze.yaidom.core._
val scope = Scope.from("xs" -> "http://www.w3.org/2001/XMLSchema", "xlink" -> "http://www.w3.org/1999/xlink", "link" -> "http://www.xbrl.org/2003/linkbase")
require(scope.isInvertible)
val path = PathBuilder.from(QName("xs:annotation") -> 2, QName("xs:appinfo") -> 0, QName("link:linkbaseRef") -> 3).build(scope)
path.toCanonicalXPath(scope) // No exception thrown
val scope2 = Scope.from("" -> "http://www.w3.org/2001/XMLSchema", "xlink" -> "http://www.w3.org/1999/xlink", "link" -> "http://www.xbrl.org/2003/linkbase")
require(scope2.isInvertible)
path.toCanonicalXPath(scope2) // Boom! Expected at least one prefix for namespace URI ...

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.