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

Adhere to Cheerio's XML mode when xmlMode option is specified #4

Open
jcdarwin opened this issue Aug 19, 2013 · 3 comments
Open

Adhere to Cheerio's XML mode when xmlMode option is specified #4

jcdarwin opened this issue Aug 19, 2013 · 3 comments

Comments

@jcdarwin
Copy link

Cheerio exposes an option "xmlMode: true", which should be used to distinguish between writing out HTML ( $.html() ) and XML ( $.xml() ).

Therefore, in method processFile:

updatedContents = $.html();  

Should become:

if (options.xmlMode) {
        updatedContents = $.xml();
} else {
        updatedContents = $.html();  
}
@cgross
Copy link
Owner

cgross commented Aug 19, 2013

I'm trying to understand the use-case you're hitting. I don't mind making the addition but I was under the assumption that cheerio would endeavor to write the document back out with the same tags as before (plus whatever your modifications were). Is it not doing this or is there some similar kind of issue?

@jcdarwin
Copy link
Author

The problem I'm having is that I'm appending some elements to an XML file,
and unfortunately some other elements are ending up malformed.

In particular I start out with:

and, without this change, end up with:

(note the lack of the self closing /).

Actually, although this suggested change fixes this problem, I strike
another problem with Cheerio (which the xmlMode doesn't help with) -- for
another element, I start out with:

2012-08-20T03:18:06Z

and end up with:

2012-08-20T03:18:06Z

(i.e. it drops the entire closing tag).

There looks to be something buried in cheerio that specifically treats meta
tags incorrectly -- I've yet to find the time to hunt it down but will do
so in the next day or two.

Jason

On Tue, Aug 20, 2013 at 2:45 AM, Chris Gross [email protected]:

I'm trying to understand the use-case you're hitting. I don't mind making
the addition but I was under the assumption that cheerio would endeavor to
write the document back out with the same tags as before (plus whatever
your modifications were). Is it not doing this or is there some similar
kind of issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/4#issuecomment-22877065
.

@inta
Copy link

inta commented May 8, 2014

Could we get this fixed? If cheerio would just write back the document unchanged, that would not be a problem, but it is removing all slashes from self closing elements (if you use $.html). That will break XHTML and polyglot documents.

A one liner like:
var updatedContents = (options.xmlMode) ? $.xml() : $.html();
would suffice …

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

3 participants