-
Notifications
You must be signed in to change notification settings - Fork 181
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
DOCTYPE declaration cannot be parsed #13
Comments
Sorry, I don't understand the issue here properly. The first line Also, do you need |
!DOCTYPE is valid XML tag, but during the convert.xml2json call parser doesn't parse it and after the conversation we lost the information from that tag. Can you keep !DOCTYPE field in JSON and after json2xml? I propose ingoreDoctype in the options and parser can convert !DOCTYPE like ![CDATA]. Example xml was't visible in my first comment. So the second line is doctype of MLP(Mobile Location Protocol), I would like to keep in the conversation. My proposal in JSON (compact mode) is following: |
|
Ok now I see the issue. Thanks for providing clear example. I am working on adding support for !DOCTYPE. Currently, I get this output (not published): {"_doctype": " svc_init SYSTEM \"MLP_SVC_INIT_300.DTD\" [<!ENTITY % extension SYSTEM \"PIF_EXTENSION_100.DTD\">%extension;]"
} As you can see, ENTITY is not parsed. {"_doctype": {
"name_": "svc_init SYSTEM \"MLP_SVC_INIT_300.DTD\"",
"extension" : "SYSTEM \"PIF_EXTENSION_100.DTD\""
}
} It seems the content of DOCTYPE is DTD which I am not very familiar with. I need to find time to study it in order to generate meaningful output. |
👍 +1 This issue, I've ran into the same problem. @nashwaan your proposal by adding DOCTYPE (proposed)Here's my XML example I would like to convert from JSON to XML. <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd"> const json = {
_declaration: {_attributes: { version: '1.0', encoding: 'utf-8' }},
_doctype: {
_comment: 'note SYSTEM "Note.dtd"'
},
}
const xml = convert.js2xml(json, { compact: true }) DOCTYPE + ENTITY (proposed)There is also <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ENTITY nbsp " ">
<!ENTITY writer "Writer: Donald Duck.">
<!ENTITY copyright "Copyright: W3Schools.">
]> const json = {
_declaration: {_attributes: { version: '1.0', encoding: 'utf-8' }},
_doctype: {
_comment: 'note',
_entity: [
{_comment: 'nbsp " "'},
{_comment: 'writer "Writer: Donald Duck."'},
{_comment: 'copyright "Copyright: W3Schools."'},
]
},
}
const xml = convert.js2xml(json, { compact: true }) |
@DenisCarriere , Thank you for your valuable feedback. I don't think using I still haven't studied DTD, but my impression is it requires a lot of parsing because of the scenarios it can support. Also, again from my shallow understanding, I think DTD influence how to parse rest of XML contents as it contains some instructions and variables (right?). What I am planning to do is to put the content of DTD in {"_doctype": " svc_init SYSTEM \"MLP_SVC_INIT_300.DTD\" [<!ENTITY % extension SYSTEM \"PIF_EXTENSION_100.DTD\">%extension;]"
} And if any needs further processing, then he can use DTD parser like https://github.com/calibr/dtd-file. Or if you are satisfied with this parser or can recommend me a good parser then I can integrate it with this |
@nashwaan Awesome stuff, agreed, maybe the 👍 I like the idea of having a simple The JS example would be even easier: const json = {
_declaration: {_attributes: { version: '1.0', encoding: 'utf-8' }},
_doctype: 'note SYSTEM "Note.dtd"'
}
const xml = convert.js2xml(json, { compact: true }) Equals <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd"> |
I have published v1.1.0 to support Please let me know whether this is good or not. |
Woot 🎉 Looks like only |
Ooops. |
Woohoo! Works like a charm. const json = {
_declaration: {_attributes: { version: '1.0', encoding: 'utf-8' }},
ServiceExceptionReport: {
_attributes: {version: '1.1.1'},
_doctype: ' ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd"',
ServiceException: {
_text: message
}
}
}
const xml = convert.js2xml(json, { compact: true, spaces: spaces }) Results<?xml version="1.0" encoding="utf-8"?>
<ServiceExceptionReport version="1.1.1">
<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd">
<ServiceException>foo</ServiceException>
</ServiceExceptionReport> Only odd thing I've noticed is you need to include a blank space in your text field, if not it immediately places the text right after |
@DenisCarriere Have implemented your suggestion and improved other things (see release notes). These are now published in v1.2.0. |
+1 awesome stuff |
@misitoth What do you think of the new approach published in the latest version? Do you have any comment or feedback before I close this issue? |
I want to convert standard MLP (Mobile Positioning Protocol) xml to JSON and back.
%extension;]>Here is the first 3 line:
<svc_init ver="3.0.0">
After it is converted to JSON:
{
"_declaration": {
"_attributes": {
"version": "1.0",
"encoding": "UTF-8"
}
},
"svc_init": {
"_attributes": {
"ver": "3.0.0"
}
convert.xml2json(xml, { compact: true, spaces: 6, ignoreCdata: false });
I lost !DOCTYPE.
Can you add ignoreDoctype to the code?
The text was updated successfully, but these errors were encountered: