You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And here is a quick modification that I threw together in xml2js.js
functiononDeclaration(declaration){if(options.ignoreDeclaration){return;}varkey=options.declarationKey;vartype="decl";if(currentElement[key]){key=options.processingKey;currentElement[key]=[];type="proc";}else{currentElement[key]={};}varitem={};item[options.nameKey]=declaration.name;while(declaration.body){varattribute=declaration.body.match(/([\w:-]+)\s*=\s*"([^"]*)"|'([^']*)'|(\w+)\s*/);if(!attribute){break;}if(!item[options.attributesKey]){item[options.attributesKey]={};}item[options.attributesKey][attribute[1]]=attribute[2];declaration.body=declaration.body.slice(attribute[0].length);// advance the string}if(type==="proc")currentElement[key].push(item);elsecurrentElement[key]=item;if(options.addParent){currentElement[options.declarationKey][options.parentKey]=currentElement;}}
OK, well I guess that could work. It would be nice if the parser could parse any valid attributes found, and also include the text, since it has the capability built in. Or is that not the intent of this library? Could it be added as a helper method?
Could we do "stylesheet": { _attributes: {}, _value: "" }?
But what you wrote above will be enough if you don't want to add this. Because then at least it will not get lost.
is a good solution, but I am thinking of adding an option like {instructionHasAttributes: true} which will parse content of the Processing Instruction as attributes. This mean the output will be:
On May 23, 2017 04:40, "Yousuf" ***@***.***> wrote:
@Arlen22 <https://github.com/arlen22>
"stylesheet": { "_attributes": {}, "_value": "" }}
is a good solution, but I am thinking of adding an option like {instructionHasAttributes:
true} which will parse content of the Processing Instruction as
attributes. This mean the output will be:
{"_instruction": {"stylesheet": {"href": "style.css"}}}
otherwise if the flag is not set, then we get this:
{"_instruction": {"stylesheet": "href=\"style.css\""}}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#17 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAa2QM1G-MUBbidB_1GKlFSppvOSgUusks5r8puVgaJpZM4Nfkyu>
.
Activity
Arlen22 commentedon May 18, 2017
The relevant line is here: https://github.com/nashwaan/xml-js/blob/master/lib/xml2js.js#L82
Arlen22 commentedon May 18, 2017
And here is a quick modification that I threw together in
xml2js.jsnashwaan commentedon May 20, 2017
Hi @Arlen22 , thanks for reporting this issue. Can you provide more examples and the expected output, please?
nashwaan commentedon May 21, 2017
@Arlen22
XML specifies that processing instruction contains just text not necessarily attributes.
This means both of the following are valid Processing Instructions:
Output json will be (in compact-form):
{"_instruction": {"stylesheet": "some random text"}}and
Output json will be (in compact-form):
{"_instruction": {"stylesheet": "href=\"style.css\""}}Note that
"_attributes"will be not generated.Arlen22 commentedon May 22, 2017
OK, well I guess that could work. It would be nice if the parser could parse any valid attributes found, and also include the text, since it has the capability built in. Or is that not the intent of this library? Could it be added as a helper method?
Could we do
"stylesheet": { _attributes: {}, _value: "" }?But what you wrote above will be enough if you don't want to add this. Because then at least it will not get lost.
nashwaan commentedon May 23, 2017
@Arlen22
is a good solution, but I am thinking of adding an option like
{instructionHasAttributes: true}which will parse content of the Processing Instruction as attributes. This mean the output will be:{"_instruction": {"stylesheet": {"href": "style.css"}}} {"_instruction": {"stylesheet": {"_attributes": {"href": "style.css"}}}} // or this?otherwise if the flag is not set, then we get this:
{"_instruction": {"stylesheet": "href=\"style.css\""}}Arlen22 commentedon May 23, 2017
nashwaan commentedon May 25, 2017
Published v1.3.2 which supports processing instruction and
{instructionHasAttributes: true}flag.converting this xml:
will produce in compact mode:
{"_instruction":{"go":"to=\"there\""}}in non-compact (expanded) mode:
{"elements":[{"type":"instruction", "name":"go", "instruction":"to=\"there\""}]}and when
{instructionHasAttributes: true}flag is set, it will produce the following in compact mode:{"_instruction":{"go":{"_attributes":{"to":"there"}}}}and this in non-compact (expanded) mode:
{"elements":[{"type":"instruction", "name":"go", "attributes":{"to":"there"}}]}@Arlen22 Please let me know if this works for you or not.
Arlen22 commentedon Jun 3, 2017
Seems to be working well. Thank you :)