Comments (11)
+1
from nori.
What if I want to get the attributes value also?
Tried this
xml_parser = Nori.new
xml_parser.parse "<FareReference ResBookDesigCode='Q'>Value</FareReference>"
Result is
{"FareReference"=>"Value"}
I wanted to retrieve ResBookDesigCode value also
from nori.
Haven't had a chance to try this yet, but off top of my head i see this being the no code change solution to my problem
[16] child = Nori::StringWithAttributes.new('active')
=> "active"
[17] child.attributes = {"xmlns:v1"=>"http://example.com"}
=> {"xmlns:v1"=>"http://example.com"}
[18] hash_for_savon = {"v1:userResponse"=> child}
=> {"v1:userResponse"=>"active"}
Savon.client(action, :message => hash_for_savon)
from nori.
Finally got around to testing this...
The code
188
189 def get_subscriber
190 child = Nori::StringWithAttributes.new('active')
191 child.attributes = {"xmlns:v1"=>"http://example.com"}
192 soap.call :retrieve, :message => {
193 'RetrieveRequest' => {
194 'ObjectType' => 'Subscriber',
195 'Properties' => [
196 "ID",
197 "PartnerKey",
198 "CreatedDate",
199 "Client.ID",
200 "Client.PartnerClientKey",
201 "EmailAddress",
202 "SubscriberKey",
203 "UnsubscribedDate",
204 "Status",
205 "EmailTypePreference"
206 ],
207 'Filter' =>
208 child
209 }
210 }
211 end
The xml...
<tns:Properties>SubscriberKey</tns:Properties>
<tns:Properties>UnsubscribedDate</tns:Properties>
<tns:Properties>Status</tns:Properties>
<tns:Properties>EmailTypePreference</tns:Properties>
<tns:Filter>active</tns:Filter>
</tns:RetrieveRequest>
Savon does not read the child attributes.
@tjarratt is this a savon bug to check for nori attributes or a nori bug for not being able to express child text nodes with attributes?
from nori.
also tried using gyoku syntax
281 def inlinetest
282 soap.call :retrieve, :message => {
283 'RetrieveRequest' => {
284 'ObjectType' => 'Subscriber',
285 'Properties' => [
286 "ID",
287 "PartnerKey",
288 "CreatedDate",
289 "Client.ID",
290 "Client.PartnerClientKey",
291 "EmailAddress",
292 "SubscriberKey",
293 "UnsubscribedDate",
294 "Status",
295 "EmailTypePreference"
296 ],
297 'Filter' => {
298 :content! => "active",
299 '@xmlns:v1' => 'http://example.com'
300 }
301 }
302 }
303 end
The xml...
<tns:Properties>UnsubscribedDate</tns:Properties>
<tns:Properties>Status</tns:Properties>
<tns:Properties>EmailTypePreference</tns:Properties>
<tns:Filter xmlns:v1="http://example.com">
<tns:content>active</tns:content>
</tns:Filter>
</tns:RetrieveRequest>
</tns:RetrieveRequestMsg>
</env:Body>
</env:Envelope>
from nori.
Sorry for taking so long to respond @barberj! I've been trying to find time to read this issue and fully understand what's going on. The only supporting evidence I can find is from a year ago discussing how attributes and text can collide. I suspect that @rubiii was describing a subtle issue with how Savon attempts to avoid collisions.
In your last example, it seemed to work correctly with you used :content!
as the key (although I'm not entirely clear what the XML should look like for this example). Does that actually work? It might be worth diving into this some more to find a better way of allowing users to do this, but to my eyes, what you posted seems fairly reasonable.
'Filter' => {
:content! => "active", '@xmlns:v1' => 'http://example.com'
}
}
from nori.
@tjarratt it didn't work. The expected xml was
<tns:Filter xmlns:v1="http://example.com">active</tns:Filter>
Looking at gyoku documentation
Using "@" keys and ":content!"
Gyoku.xml(
"foo/" => {
:@bar => "1",
:@biz => "2",
:@baz => "3",
:content! => ""
})
# => "<foo baz=\"3\" bar=\"1\" biz=\"2\"/>"
from nori.
I've found a problem while parsing this kind of attributes, and my guess is that it is related to this issue.
This is what I've seen while debugging: {:total=>[<totalcode="EUR">166141</total>]}
The original XML was like <Total Code="EUR">166141</Total>
, so at some point it seems to be wrongly merging the first attribute with the element itself, producing the problem and being this attribute ignored.
I'm still trying to find the bug in Nori's code.
from nori.
What if I want to get the attributes value also?
Tried thisxml_parser = Nori.new xml_parser.parse "<FareReference ResBookDesigCode='Q'>Value</FareReference>"
Result is
{"FareReference"=>"Value"}
I wanted to retrieve ResBookDesigCode value also
@yllihv27 I came to the issues here trying to find the answer to the same thing. I'm trying to use Savon with an API that returns tags that have attributes which defines what the text in the tags actually mean. I was trying to figure out how to not lose the attributes when converting the response body to a hash. Have you found any way?
from nori.
@yllihv27 @anirbanmu I had the same use-case and found the solution here: #50 (comment). You can access the attributes via the Nori::StringWithAttributes#attributes
method.
from nori.
Hi. I've updated the readme here with examples of how to access attributes from a text node, since it's not super obvious from repl that the result is of type Nori::StringWithAttributes#attributes
from nori.
Related Issues (20)
- dont monkeypatch String#snakecase HOT 6
- Nori doesn't handle lists of named attributes and values HOT 2
- Strings as Nori::StringWithAttributes HOT 8
- xsi:nil="true" nodes not nil when additional attributes present HOT 2
- Why add Hash#to_params HOT 1
- Make advanced type casting actually advanced HOT 2
- strip error HOT 3
- advance_type_casting regex fails to parse time like fields HOT 3
- XML Parsing fails with unescaped ampersand in content (not tag) HOT 1
- Breaking change between 2.4.0 and 2.6.0 HOT 1
- Nori dynamic require breaks in Jruby HOT 3
- does not work with plain tags and whitespace
- Selective disabling of advanced_typcasting for certain attributes
- Strange error when passing malformed xml
- empty_tag_value not obeying xsi:nil ?
- Raise on error?
- REXML parsing error HOT 3
- strip_namespaces doesn't work for attributes HOT 1
- Inconsistent types when parsing empty tags HOT 2
- Nori::StringWithAttributes should implement `#as_json` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nori.