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

doesn't parse correctly if whitespaces exist #8

Closed
flosse opened this issue Jan 2, 2012 · 4 comments
Closed

doesn't parse correctly if whitespaces exist #8

flosse opened this issue Jan 2, 2012 · 4 comments

Comments

@flosse
Copy link
Contributor

flosse commented Jan 2, 2012

ltx.parse("<x> </x>").children.length is 1 and correct (as long as whitespace characters where threated as children)
ltx.parse("<x> <y> </y> </x>").children.length is 3 and NOT correct; it should be 1

The children and the text of an element are treated the same way. Maybe we should explicitly separate them? So an element has either some children (el.children) or content (el.content) but not both.

@astro
Copy link
Member

astro commented Jan 4, 2012

Not sure I understand. The 2nd example has 3 children: a text node, the <y/> child, and another text node. Why should this be 1?

Squashing whitespace around elements may not be appropriate for all use cases. In XHTML, <b>Hello</b><i>World</i> would be rendered differently from <b>Hello</b> <i>World</i>.

@flosse
Copy link
Contributor Author

flosse commented Jan 4, 2012

Ok, You're right!
I thought that whitespace/text between two tags (e.g. <a>foo<b/> </a>) is not valid.
So in case my client accidentally added whitespaces (<value> <int>4</int></value>) I'll have problems if I try to access the child by just using it's order

valueElement.children[0] // returns ' ' instead of 4

As long as I know the tag name I can use getChildText("int") otherwise it might be great if there were a method like el.trim() that removes all whitespaces that are not within a tag?

@astro
Copy link
Member

astro commented Jan 4, 2012

Generally I'd suggest using valueElement.getChild('int'). That way you would assert that the first child is <int/> indeed, not anything else.

A patch for a handy trim() will be accepted!

@astro astro closed this as completed Jan 4, 2012
@astro
Copy link
Member

astro commented Jan 4, 2012

BTW. As an european open source hacker, do you have any plans regarding FOSDEM 2012? I won't be there, but @dodo is planning to go!

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

No branches or pull requests

2 participants