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
{{ message }}
Repository navigation
Enclosing XML Tag Name Unavailable as Object Name When Unmarshaled #201
Hello. When unmarshalling an XML string, eg. var something = unmarshaller.unmarshalString('<thing>Some text.</thing>'); , the overall enclosing XML tag name, ie. <thing>, is not available in the unmarshalled JS object, ie. thing.value.data is unavailable in the JS script. Instead the overall enclosing XML tag name is replaced by the name of the variable coded in the assignment to the return value of the unmarshaller, ie. something , so the value enclosed by the XML is referenced in the JS script by something.value.data . Unless I'm missing something in the unmarshalling process that preserves the outermost enclosing tag name.
var One = {
name: 'One',
typeInfos: [{
type: 'classInfo',
localName: 'ValueType',
propertyInfos: [{
name: 'data',
type: 'value',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'thing',
typeInfo: 'One.ValueType'
}]
};
var context = new Jsonix.Context([One]);
var unmarshaller = context.createUnmarshaller();
var something = unmarshaller.unmarshalString('<thing>Some text.</thing>');
console.log("something:\n");
console.log(something);
console.log("something data value:");
console.log(something.value.data);
Have you actually tried looking in something? Because the data you're interested in is there. The qualified name of the element is available as something.name. something.name.localPart gives you thing.
Yes, I dumped the whole JS object structure, and I saw the enclosing tag name is in the properties tree. I guess that's the only way, since the unmarshaller doesn't have access to the JS script's namespace in which to set the unmarshalled object's name. Though maybe a new method, like unmarshalString(xmlStr, 'something') or unmarshalString(xmlStr, something) might help keep the JS script simpler.
In var something = unmarshaller.unmarshalString('<thing>Some text.</thing>'); the unmarshalled object's name is something, in the JS script's namespace. The unmarshaller populates the object the unmarshaller returns, but the unmarshaller doesn't have access to the JS script's namespace, so the unmarshaller can't name the returned object.
unmarshalString(xmlStr, 'something') can't name the returned object either, I was mistaken to suggest it. But unmarshalString(xmlStr, something) could use an already created something, but that's not better than the existing var something = unmarshaller.unmarshalString('<thing>Some text.</thing>');. Neither suggestion is a good one.
The only way I can think of to allow the outermost enclosing tag name to be used in the JS script to refer to the unmarshalled object would be for the unmarshaller to return an object that contains the entire unmarshalled property tree as a property. Then the name assigned in the JS script would refer to the object containing the actual unmarshalled object. Eg.
var something = unmarshaller.unmarshalString('<thing><who><firstName>Some</firstName><lastName>Name</lastName></who><what>Some text.</what></thing>');`
var lastName = something.thing.who.lastName;
That structure would make walking the property tree reference the outermost container's name in the same way that all the properties in its property tree are referenced, useful in recursion/loops and other logic walking the tree. Other metadata could be stored in the outermost container in a property next to the property tree root, eg. if(something.source === 'string').
To be honest, I am not quite sure which problem you're trying to solve. Please show a piece of code which does not work now but which you'd like to work.
On Sun, 2018-09-23 at 18:47 +0000, Alexey Valikov wrote:
To be honest, I am not quite sure which problem you're trying to
solve. Please show a piece of code which does not work now but which
you'd like to work.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c5
5493e4bb","name":"GitHub"},"entity":{"external_key":"github/highsourc
e/jsonix","title":"highsource/jsonix","subtitle":"GitHub
repository","main_image_url":"https://assets-cdn.github.com/images/em
ail/message_cards/header.png","avatar_image_url":"https://assets-
cdn.github.com/images/email/message_cards/avatar.png","action":{"name
":"Open in GitHub","url":"https://github.com/highsource/jsonix"}},"up
***@***.*** in #201:
To be honest, I am not quite sure which problem you're trying to
solve. Please show a piece of code which does not work now but which
you'd like to work."}],"action":{"name":"View Issue","url":"https://g
ithub.com/highsource/jsonix/issues/201#issuecomment-423838320"}}}
[
{
***@***.***": "http://schema.org",
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "#201 (comment)
nt-423838320",
"url": "#201 (comment)-
423838320",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
***@***.***": "MessageCard",
***@***.***": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [highsource/jsonix] Enclosing XML Tag Name Unavailable
as Object Name When Unmarshaled (#201)",
"sections": [
{
"text": "",
"activityTitle": "**Alexey Valikov**",
"activityImage": "https://assets-cdn.github.com/images/email/message_
cards/avatar.png",
"activitySubtitle": ***@***.***",
"facts": [
]
}
],
"potentialAction": [
{
"name": "Add a comment",
***@***.***": "ActionCard",
"inputs": [
{
"isMultiLine": true,
***@***.***": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
***@***.***": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\":
\"IssueComment\",\n\"repositoryFullName\":
\"highsource/jsonix\",\n\"issueId\": 201,\n\"IssueComment\":
\"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "#201 (comment)-
423838320"
}
],
***@***.***": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
***@***.***": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\":
382457805\n}"
}
],
"themeColor": "26292E"
}
]
Activity
highsource commentedon Sep 22, 2018
Have you actually tried looking in
something? Because the data you're interested in is there. The qualified name of the element is available assomething.name.something.name.localPartgives youthing.Here's a Fiddle for this:
https://jsfiddle.net/lexi/vrkefbd5/
MatthewGitter commentedon Sep 22, 2018
Yes, I dumped the whole JS object structure, and I saw the enclosing tag name is in the properties tree. I guess that's the only way, since the unmarshaller doesn't have access to the JS script's namespace in which to set the unmarshalled object's name. Though maybe a new method, like
unmarshalString(xmlStr, 'something')orunmarshalString(xmlStr, something)might help keep the JS script simpler.highsource commentedon Sep 22, 2018
I'm not quite sure what "unmarshalled object's name" is and what
unmarshalString(xmlStr, 'something')should do.MatthewGitter commentedon Sep 23, 2018
In
var something = unmarshaller.unmarshalString('<thing>Some text.</thing>');the unmarshalled object's name issomething, in the JS script's namespace. The unmarshaller populates the object the unmarshaller returns, but the unmarshaller doesn't have access to the JS script's namespace, so the unmarshaller can't name the returned object.unmarshalString(xmlStr, 'something')can't name the returned object either, I was mistaken to suggest it. ButunmarshalString(xmlStr, something)could use an already createdsomething, but that's not better than the existingvar something = unmarshaller.unmarshalString('<thing>Some text.</thing>');. Neither suggestion is a good one.The only way I can think of to allow the outermost enclosing tag name to be used in the JS script to refer to the unmarshalled object would be for the unmarshaller to return an object that contains the entire unmarshalled property tree as a property. Then the name assigned in the JS script would refer to the object containing the actual unmarshalled object. Eg.
That structure would make walking the property tree reference the outermost container's name in the same way that all the properties in its property tree are referenced, useful in recursion/loops and other logic walking the tree. Other metadata could be stored in the outermost container in a property next to the property tree root, eg.
if(something.source === 'string').highsource commentedon Sep 23, 2018
To be honest, I am not quite sure which problem you're trying to solve. Please show a piece of code which does not work now but which you'd like to work.
MatthewGitter commentedon Sep 24, 2018