Git Product home page Git Product logo

Comments (11)

bdwyertech avatar bdwyertech commented on June 8, 2024 3

+1

from nori.

yllihv27 avatar yllihv27 commented on June 8, 2024 1

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.

barberj avatar barberj commented on June 8, 2024

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.

barberj avatar barberj commented on June 8, 2024

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.

barberj avatar barberj commented on June 8, 2024

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.

tjarratt avatar tjarratt commented on June 8, 2024

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.

barberj avatar barberj commented on June 8, 2024

@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.

xurde avatar xurde commented on June 8, 2024

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.

anirbanmu avatar anirbanmu commented on June 8, 2024

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

@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.

trezona-lecomte avatar trezona-lecomte commented on June 8, 2024

@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.

pcai avatar pcai commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.