Can't find any node using Nokogiri - ruby

I have [Content_Types].xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="xml" ContentType="application/xml"/>
<Default Extension="jpeg" ContentType="image/jpeg"/>
<Default Extension="png" ContentType="image/png"/>
<Default Extension="jpg" ContentType="image/jpeg"/>
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
<Override PartName="/customXml/itemProps1.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml"/>
<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
<Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
<Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/>
<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>
<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/>
<Override PartName="/word/header1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"/>
<Override PartName="/word/footer1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"/>
<Override PartName="/word/header2.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"/>
<Override PartName="/word/footer2.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"/>
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
<Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
</Types>
I've loaded it using Nokogiri:
doc = File.open("[Content_Types].xml") { |f| Nokogiri::XML(f) }
I want to find the <Default Extension="png" ContentType="image/png"/> node but I can't find anything:
irb(main):048:0> doc.xpath('//Default')
=> []
irb(main):049:0> doc.xpath('//Override')
=> []
irb(main):050:0> doc.xpath('//Types')
=> []
irb(main):051:0> doc.xpath('Types')
=> []
Why?
The xml is loaded correctly:
irb(main):003:0> doc
=>
#<Nokogiri::XML::Document:0x3fcddd413ad0 name="document" children=[#<Nokogiri::XML::Element:0x3fcddd41347c name="Types" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> children=[#<Nokogiri::XML::Text:0x3fcddd412f18 "\n\n ">, #<Nokogiri::XML::Element:0x3fcddd412e14 name="Default" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd412d9c name="Extension" value="xml">, #<Nokogiri::XML::Attr:0x3fcddd412d88 name="ContentType" value="application/xml">]>, #<Nokogiri::XML::Text:0x3fcddd4126bc "\n ">, #<Nokogiri::XML::Element:0x3fcddd413558 name="Default" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd40ffac name="Extension" value="rels">, #<Nokogiri::XML::Attr:0x3fcddd40ff84 name="ContentType" value="application/vnd.openxmlformats-package.relationships+xml">]>, #<Nokogiri::XML::Text:0x3fcddd40ef08 "\n ">, #<Nokogiri::XML::Element:0x3fcddd40eddc name="Default" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd40ecec name="Extension" value="jpeg">, #<Nokogiri::XML::Attr:0x3fcddd40ecc4 name="ContentType" value="image/jpeg">]>, #<Nokogiri::XML::Text:0x3fcddd40bca4 "\n ">, #<Nokogiri::XML::Element:0x3fcddd40bb78 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd40bac4 name="PartName" value="/word/document.xml">, #<Nokogiri::XML::Attr:0x3fcddd40ba88 name="ContentType" value="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">]>, #<Nokogiri::XML::Text:0x3fcddd40a8cc "\n ">, #<Nokogiri::XML::Element:0x3fcddd40a7f0 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd40a778 name="PartName" value="/word/styles.xml">, #<Nokogiri::XML::Attr:0x3fcddd40a764 name="ContentType" value="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml">]>, #<Nokogiri::XML::Text:0x3fcddd099d00 "\n ">, #<Nokogiri::XML::Element:0x3fcddd099bc0 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd099b34 name="PartName" value="/word/settings.xml">, #<Nokogiri::XML::Attr:0x3fcddd099b20 name="ContentType" value="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml">]>, #<Nokogiri::XML::Text:0x3fcddd098e8c "\n ">, #<Nokogiri::XML::Element:0x3fcddd098d60 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd098cc0 name="PartName" value="/word/webSettings.xml">, #<Nokogiri::XML::Attr:0x3fcddd098cac name="ContentType" value="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml">]>, #<Nokogiri::XML::Text:0x3fcddd08ded8 "\n ">, #<Nokogiri::XML::Element:0x3fcddd08dd98 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd08dce4 name="PartName" value="/word/fontTable.xml">, #<Nokogiri::XML::Attr:0x3fcddd08dca8 name="ContentType" value="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml">]>, #<Nokogiri::XML::Text:0x3fcddd08cdf8 "\n ">, #<Nokogiri::XML::Element:0x3fcddd08cd1c name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd08cc54 name="PartName" value="/word/theme/theme1.xml">, #<Nokogiri::XML::Attr:0x3fcddd08cc40 name="ContentType" value="application/vnd.openxmlformats-officedocument.theme+xml">]>, #<Nokogiri::XML::Text:0x3fcddd08c0d8 "\n ">, #<Nokogiri::XML::Element:0x3fcddd08c010 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd089fa4 name="PartName" value="/docProps/core.xml">, #<Nokogiri::XML::Attr:0x3fcddd089f90 name="ContentType" value="application/vnd.openxmlformats-package.core-properties+xml">]>, #<Nokogiri::XML::Text:0x3fcddd089388 "\n ">, #<Nokogiri::XML::Element:0x3fcddd089248 name="Override" namespace=#<Nokogiri::XML::Namespace:0x3fcddd4133b4 href="http://schemas.openxmlformats.org/package/2006/content-types"> attributes=[#<Nokogiri::XML::Attr:0x3fcddd089144 name="PartName" value="/docProps/app.xml">, #<Nokogiri::XML::Attr:0x3fcddd089130 name="ContentType" value="application/vnd.openxmlformats-officedocument.extended-properties+xml">]>]>]>

On the "Searching a XML/HTML document" page on the Nokogiri site, there's an ATOM example
Let’s take this atom feed for example:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>
If we stick to the convention, we can grab all title tags like this
#doc.xpath('//xmlns:title') # => ["<title>Example Feed</title>", "<title>Atom-Powered Robots Run Amok</title>"]
Since your example input has
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
It should work to do
puts doc.xpath("//xmlns:Default[#Extension='png']")
# <Default Extension="png" ContentType="image/png"/>
Alternatively, you can use css instead
puts doc.css("Types Default[Extension='png']")
# <Default Extension="png" ContentType="image/png"/>
There's also a section on the page about not dealing with namespaces if you're interested

Related

Unable to toggle editor style after manually editing xcdatamodel/content file

After manually editing the xcdatamodel/content due to a merge conflict I'm able to open and run the project just fine, but I'm unable to toggle the toggle the editor style to show the "object relations diagram"
I'm using Xcode 13.4.1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21279" systemVersion="21G115" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Foo" representedClassName=".foo" syncable="YES">
...
</entity>
<entity name="Bar" representedClassName=".bar" syncable="YES">
...
</entity>
<entity name="FooBar" representedClassName=".fooBar" syncable="YES">
...
<fetchIndex name="fooie">
<fetchIndexElement property="fooeee" type="Binary" order="ascending"/>
</fetchIndex>
</entity>
<entity name="BarFoo" representedClassName=".barFoo" syncable="YES">
<fetchIndex name="byPropertyIndex">
<fetchIndexElement property="bla bla bla" type="Binary" order="descending"/>
</fetchIndex>
</entity>
<elements>
<element name="Foo" positionX="0" positionY="0" width="0" height="0"/>
<element name="Bar" positionX="0" positionY="0" width="0" height="0"/>
<element name="FooBar" positionX="0" positionY="0" width="0" height="0"/>
<element name="BarFoo" positionX="0" positionY="0" width="0" height="0"/>
</elements>
</model>
Any Idea what is going on here? How can I get xcode to open the object Diagram for this model version?

Making Office 365 addin manifests that actually work when deployed

We are a Microsoft partner (although we've never had any value derived from it). We have desktop office VSTO addins for classifying documents that we sell to governments but moved to online given their 365 cloud push. The manifest generation process is very irritating. Manifests that previously worked stop working arbitrarily. We've found the office 365 addin development process disappointing to be frank. Dealing with this stack is like a black hole of apathy and malaise. It reminds me of trying to compile my C program on a server back in 2000 and getting arcane errors and not knowing what went wrong. If I was in charge I would advise our management to drop this stack and find something else to sell, because it's just not worth the headache. We're bleeding money with multiple devs and QA trying to figure out why a blob of xml isn't working.
We looked at the yeoman generator's output and tried to compare it to our own, but didn't see much difference. We keep getting random 1300X errors (that change depending on which tenant we're on). After looking at the code here https://github.com/OfficeDev/Office-Addin-Scripts I can't help but laugh at your folly. You wrongly chose configuration (the manifest) over code. Then you made a bunch of hand-coded xml handling instead of creating a general XSD-based schema editing tool (which apparently previously existed but now does not).
That said. I get that you're exporting your internal concerns onto platform users, but I need to sell software and I can't do that when I can't get our addin deployed so we can test it. Manifests work when inserted manually for debug, but not when deployed. What gives?
Can anybody tell me what's wrong with this outlook manifest? Why don't it deploy?
edit in response to comments:
Please bear with me as I gather info from our IT people as I posted this on their behalf because they were frustrated but were also hesitant to post here due to previous bad experiences etc. The manifest had many issues. The errors were different for word vs outlook. Sometimes we would get validation errors with no information (even though the addin passed the validation tool). Other times it threw 13004 (if I remember correctly). I suspect the validation tools don't fully do URL checking until deployment. A missing help URL threw us as well. I will take the latest manifests we have and diff them with the sample i provided and compare that to the answer below. It appears as though they eventually got it working after a lot of trial and error...
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MailApp">
<Id>22222222-1111-1111-1111-11111111ABCD</Id>
<Version>1.0.0.0</Version>
<ProviderName>Banana</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Banana Classifier">
<Override Locale="fr-CA" Value="Classifieur Banana" />
<Override Locale="fr-FR" Value="Classifieur Banana" />
</DisplayName>
<Description DefaultValue="Fruit Banana Classifier">
<Override Locale="fr-CA" Value="Classifieur Banana de Fruit" />
<Override Locale="fr-FR" Value="Classifieur Banana de Fruit" />
</Description>
<IconUrl DefaultValue="https://localhost:3000/assets/Banana_32.png" />
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/Banana_80.png" />
<SupportUrl DefaultValue="https://www.Fruitsolutions.com/" />
<AppDomains>
<AppDomain>https://login.microsoftonline.com/</AppDomain>
<AppDomain>https://localhost:3000/</AppDomain>
<AppDomain>https://www.Fruitsolutions.com/</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Mailbox" />
</Hosts>
<Requirements>
<Sets>
<Set Name="Mailbox" MinVersion="1.1" />
</Sets>
</Requirements>
<FormSettings>
<Form xsi:type="ItemRead">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/index.html" />
<RequestedHeight>450</RequestedHeight>
</DesktopSettings>
</Form>
<Form xsi:type="ItemEdit">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/index.html" />
</DesktopSettings>
</Form>
</FormSettings>
<Permissions>ReadWriteMailbox</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" />
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
</Rule>
<DisableEntityHighlighting>false</DisableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Fruit.DesktopFunctionFile.Url" />
<ExtensionPoint xsi:type="CustomPane">
<RequestedHeight>450</RequestedHeight>
<SourceLocation resid="Fruit.Taskpane.Url" />
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" />
</Rule>
</ExtensionPoint>
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="Fruit.Group1Label" />
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="Fruit.TaskpaneButton.Label" />
<Supertip>
<Title resid="Fruit.TaskpaneButton.Label" />
<Description resid="Fruit.TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Fruit.tpicon_16x16" />
<bt:Image size="32" resid="Fruit.tpicon_32x32" />
<bt:Image size="80" resid="Fruit.tpicon_80x80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Fruit.Taskpane.Url" />
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Fruit.tpicon_16x16" DefaultValue="https://localhost:3000/assets/Banana_16.png" />
<bt:Image id="Fruit.tpicon_32x32" DefaultValue="https://localhost:3000/assets/Banana_32.png" />
<bt:Image id="Fruit.tpicon_80x80" DefaultValue="https://localhost:3000/assets/Banana_80.png" />
</bt:Images>
<bt:Urls>
<bt:Url id="Fruit.Taskpane.Url" DefaultValue="https://localhost:3000/index.html" />
<bt:Url id="Fruit.GetStarted.LearnMoreUrl" DefaultValue="https://www.Fruitsolutions.com/" />
<bt:Url id="Fruit.DesktopFunctionFile.Url" DefaultValue="https://localhost:3000/function-file/function-file.html" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="Fruit.TaskpaneButton.Label" DefaultValue="Banana Classifier">
<bt:Override Locale="fr-CA" Value="Classifieur Banana" />
<bt:Override Locale="fr-FR" Value="Classifieur Banana" />
</bt:String>
<bt:String id="Fruit.Group1Label" DefaultValue="Fruit">
<bt:Override Locale="fr-CA" Value="Fruit" />
<bt:Override Locale="fr-FR" Value="Fruit" />
</bt:String>
<bt:String id="Fruit.GetStarted.Title" DefaultValue="Fruit Banana Classifier">
<bt:Override Locale="fr-CA" Value="Classifieur Banana de Fruit" />
<bt:Override Locale="fr-FR" Value="Classifieur Banana de Fruit" />
</bt:String>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="Fruit.TaskpaneButton.Tooltip" DefaultValue="Click to Show the Fruit Banana Classifier">
<bt:Override Locale="fr-CA" Value="Cliquer pour afficher le Classifieur Banana" />
<bt:Override Locale="fr-FR" Value="Cliquer pour afficher le Classifieur Banana" />
</bt:String>
<bt:String id="Fruit.GetStarted.Description" DefaultValue="The Fruit Banana Classifier Add-in loaded successfully. Click the 'Banana Classifier' button to get started.">
<bt:Override Locale="fr-CA" Value="Le complément Classifieur Banana a été chargé avec succès. Veuillez cliquer sur le bouton 'Classifieur Banana' pour débuter." />
<bt:Override Locale="fr-FR" Value="Le complément Classifieur Banana a été chargé avec succès. Veuillez cliquer sur le bouton 'Classifieur Banana' pour débuter." />
</bt:String>
</bt:LongStrings>
</Resources>
<WebApplicationInfo>
<Id>22222222-1111-1111-1111-11111111ABCD</Id>
<Resource>api://localhost:3000/Banana_CLASSIFIER_AZURE_APPLICATION_ID</Resource>
<Scopes>
<Scope>Files.ReadWrite.All</Scope>
<Scope>Mail.Read</Scope>
<Scope>Mail.ReadWrite</Scope>
<Scope>Mail.ReadWrite.Shared</Scope>
<Scope>offline_access</Scope>
<Scope>openid</Scope>
<Scope>profile</Scope>
<Scope>Sites.ReadWrite.All</Scope>
<Scope>User.Read</Scope>
</Scopes>
</WebApplicationInfo>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>
I installed your manifest above to an exchange account, and it reported the id was invalid, and that the resources needed to be under your base url (fruitsolutions). I corrected those (with dummy values), and then it uploaded to the account, and loaded the button to Outlook.
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MailApp">
<Id>22222222-1111-1111-1111-11111111ABCD</Id>
<Version>1.0.0.0</Version>
<ProviderName>Banana</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Banana Classifier">
<Override Locale="fr-CA" Value="Classifieur Banana" />
<Override Locale="fr-FR" Value="Classifieur Banana" />
</DisplayName>
<Description DefaultValue="Fruit Banana Classifier">
<Override Locale="fr-CA" Value="Classifieur Banana de Fruit" />
<Override Locale="fr-FR" Value="Classifieur Banana de Fruit" />
</Description>
<IconUrl DefaultValue="https://localhost:3000/assets/Banana_32.png" />
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/Banana_80.png" />
<SupportUrl DefaultValue="https://www.Fruitsolutions.com/" />
<AppDomains>
<AppDomain>https://login.microsoftonline.com/</AppDomain>
<AppDomain>https://localhost:3000/</AppDomain>
<AppDomain>https://www.Fruitsolutions.com/</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Mailbox" />
</Hosts>
<Requirements>
<Sets>
<Set Name="Mailbox" MinVersion="1.1" />
</Sets>
</Requirements>
<FormSettings>
<Form xsi:type="ItemRead">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/index.html" />
<RequestedHeight>450</RequestedHeight>
</DesktopSettings>
</Form>
<Form xsi:type="ItemEdit">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/index.html" />
</DesktopSettings>
</Form>
</FormSettings>
<Permissions>ReadWriteMailbox</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" />
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
</Rule>
<DisableEntityHighlighting>false</DisableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Fruit.DesktopFunctionFile.Url" />
<ExtensionPoint xsi:type="CustomPane">
<RequestedHeight>450</RequestedHeight>
<SourceLocation resid="Fruit.Taskpane.Url" />
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" />
</Rule>
</ExtensionPoint>
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="Fruit.Group1Label" />
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="Fruit.TaskpaneButton.Label" />
<Supertip>
<Title resid="Fruit.TaskpaneButton.Label" />
<Description resid="Fruit.TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Fruit.tpicon_16x16" />
<bt:Image size="32" resid="Fruit.tpicon_32x32" />
<bt:Image size="80" resid="Fruit.tpicon_80x80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Fruit.Taskpane.Url" />
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Fruit.tpicon_16x16" DefaultValue="https://www.Fruitsolutions.com/assets/Banana_16.png" />
<bt:Image id="Fruit.tpicon_32x32" DefaultValue="https://www.Fruitsolutions.com/assets/Banana_32.png" />
<bt:Image id="Fruit.tpicon_80x80" DefaultValue="https://www.Fruitsolutions.com/assets/Banana_80.png" />
</bt:Images>
<bt:Urls>
<bt:Url id="Fruit.Taskpane.Url" DefaultValue="https://www.Fruitsolutions.com/index.html" />
<bt:Url id="Fruit.GetStarted.LearnMoreUrl" DefaultValue="https://www.Fruitsolutions.com/" />
<bt:Url id="Fruit.DesktopFunctionFile.Url" DefaultValue="https://www.Fruitsolutions.com/function-file/function-file.html" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="Fruit.TaskpaneButton.Label" DefaultValue="Banana Classifier">
<bt:Override Locale="fr-CA" Value="Classifieur Banana" />
<bt:Override Locale="fr-FR" Value="Classifieur Banana" />
</bt:String>
<bt:String id="Fruit.Group1Label" DefaultValue="Fruit">
<bt:Override Locale="fr-CA" Value="Fruit" />
<bt:Override Locale="fr-FR" Value="Fruit" />
</bt:String>
<bt:String id="Fruit.GetStarted.Title" DefaultValue="Fruit Banana Classifier">
<bt:Override Locale="fr-CA" Value="Classifieur Banana de Fruit" />
<bt:Override Locale="fr-FR" Value="Classifieur Banana de Fruit" />
</bt:String>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="Fruit.TaskpaneButton.Tooltip" DefaultValue="Click to Show the Fruit Banana Classifier">
<bt:Override Locale="fr-CA" Value="Cliquer pour afficher le Classifieur Banana" />
<bt:Override Locale="fr-FR" Value="Cliquer pour afficher le Classifieur Banana" />
</bt:String>
<bt:String id="Fruit.GetStarted.Description" DefaultValue="The Fruit Banana Classifier Add-in loaded successfully. Click the 'Banana Classifier' button to get started.">
<bt:Override Locale="fr-CA" Value="Le complément Classifieur Banana a été chargé avec succès. Veuillez cliquer sur le bouton 'Classifieur Banana' pour débuter." />
<bt:Override Locale="fr-FR" Value="Le complément Classifieur Banana a été chargé avec succès. Veuillez cliquer sur le bouton 'Classifieur Banana' pour débuter." />
</bt:String>
</bt:LongStrings>
</Resources>
<WebApplicationInfo>
<Id>22222222-1111-1111-1111-11111111ABCD</Id>
<Resource>https://www.Fruitsolutions.com/Banana_CLASSIFIER_AZURE_APPLICATION_ID</Resource>
<Scopes>
<Scope>Files.ReadWrite.All</Scope>
<Scope>Mail.Read</Scope>
<Scope>Mail.ReadWrite</Scope>
<Scope>Mail.ReadWrite.Shared</Scope>
<Scope>offline_access</Scope>
<Scope>openid</Scope>
<Scope>profile</Scope>
<Scope>Sites.ReadWrite.All</Scope>
<Scope>User.Read</Scope>
</Scopes>
</WebApplicationInfo>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>

UiPath Automating clicks of a list sequentially on a webpage

This is the website I am looking at.
In this website there is a list of companies where I can click into them:
Click the name of the company
Click the "Annual Report" button
Click the "Annual Report & CG Report - 2018" link
There are 788 companies in this list and I wish to repeat this process for the whole list.
Is this possible?
Currently I used Data Scraping -> Attach Browser url -> Extract Structured Data. After that I am stuck.
For me that sounds pretty simple:
go to overview
download the list via data scraping
for each on that list and surf to each of those urls
on the url do the things you said, like clicking the Annual Report and then Annual Report & CG Report - 2018
So the usual structure of a UiPath process is this one:
This is the Main.xaml visual overview that works on your example:
And this is the Main.xaml code:
<Activity mc:Ignorable="sap sap2010" x:Class="Main" mva:VisualBasic.Settings="{x:Null}" sap:VirtualizedContainerService.HintSize="530,1075" sap2010:WorkflowViewState.IdRef="ActivityBuilder_1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:ui="http://schemas.uipath.com/workflow/activities" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextExpression.NamespacesForImplementation>
<scg:List x:TypeArguments="x:String" Capacity="22">
<x:String>System.Activities</x:String>
<x:String>System.Activities.Statements</x:String>
<x:String>System.Activities.Expressions</x:String>
<x:String>System.Activities.Validation</x:String>
<x:String>System.Activities.XamlIntegration</x:String>
<x:String>Microsoft.VisualBasic</x:String>
<x:String>Microsoft.VisualBasic.Activities</x:String>
<x:String>System</x:String>
<x:String>System.Collections</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Diagnostics</x:String>
<x:String>System.Drawing</x:String>
<x:String>System.IO</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Net.Mail</x:String>
<x:String>System.Xml</x:String>
<x:String>System.Xml.Linq</x:String>
<x:String>UiPath.Core</x:String>
<x:String>UiPath.Core.Activities</x:String>
<x:String>System.Windows.Markup</x:String>
<x:String>UiPath.CV</x:String>
</scg:List>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<scg:List x:TypeArguments="AssemblyReference" Capacity="18">
<AssemblyReference>System.Activities</AssemblyReference>
<AssemblyReference>Microsoft.VisualBasic</AssemblyReference>
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Drawing</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>PresentationFramework</AssemblyReference>
<AssemblyReference>WindowsBase</AssemblyReference>
<AssemblyReference>PresentationCore</AssemblyReference>
<AssemblyReference>System.Xaml</AssemblyReference>
<AssemblyReference>UiPath.System.Activities</AssemblyReference>
<AssemblyReference>UiPath.UiAutomation.Activities</AssemblyReference>
<AssemblyReference>UiPath.CV</AssemblyReference>
<AssemblyReference>System.ValueTuple</AssemblyReference>
<AssemblyReference>System.Data.DataSetExtensions</AssemblyReference>
</scg:List>
</TextExpression.ReferencesForImplementation>
<Sequence sap:VirtualizedContainerService.HintSize="510,975" sap2010:WorkflowViewState.IdRef="Sequence_3">
<Sequence.Variables>
<Variable x:TypeArguments="sd:DataTable" Default="[New System.Data.DataTable]" Name="ExtractDataTable" />
<Variable x:TypeArguments="ui:Browser" Name="Browser" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<ui:OpenBrowser CommunicationMethod="{x:Null}" Hidden="{x:Null}" NewSession="{x:Null}" Private="{x:Null}" BrowserType="Firefox" DisplayName="Open Browser" sap:VirtualizedContainerService.HintSize="468,351" sap2010:WorkflowViewState.IdRef="OpenBrowser_1" UiBrowser="[Browser]" Url="https://www.bursamalaysia.com/trade/trading_resources/listing_directory/main_market">
<ui:OpenBrowser.Body>
<ActivityAction x:TypeArguments="x:Object">
<ActivityAction.Argument>
<DelegateInArgument x:TypeArguments="x:Object" Name="ContextTarget" />
</ActivityAction.Argument>
<ui:BrowserScope Browser="{x:Null}" SearchScope="{x:Null}" TimeoutMS="{x:Null}" UiBrowser="{x:Null}" BrowserType="Firefox" DisplayName="Attach Browser" sap:VirtualizedContainerService.HintSize="434,252" sap2010:WorkflowViewState.IdRef="BrowserScope_2" InformativeScreenshot="49520eaf054f3a2d88e58aa9f0f1cdb7" Selector="<html app='firefox.exe' title='Main Market' />">
<ui:BrowserScope.Body>
<ActivityAction x:TypeArguments="x:Object">
<ActivityAction.Argument>
<DelegateInArgument x:TypeArguments="x:Object" Name="ContextTarget" />
</ActivityAction.Argument>
<ui:ExtractData DelayBetweenPagesMS="{x:Null}" ContinueOnError="True" DataTable="[ExtractDataTable]" DisplayName="Extract Structured Data" ExtractMetadata="<extract><column exact='1' name='Name' attr='text' name2='URL' attr2='href'><webctrl tag='tr'/><webctrl tag='td' class=' text-left position-relative'/><webctrl tag='a' class='company-announcement-link' idx='1'/></column></extract>" sap:VirtualizedContainerService.HintSize="334,106" sap2010:WorkflowViewState.IdRef="ExtractData_2" MaxNumberOfResults="100" NextLinkSelector="<webctrl parentid='DataTables_Table_0_next' tag='A' />" SimulateClick="True">
<ui:ExtractData.Target>
<ui:Target ClippingRegion="{x:Null}" Element="{x:Null}" InformativeScreenshot="c9106f042e4e67a92a010ed284896366" Selector="<webctrl parentid='DataTables_Table_0' tag='TBODY' />" WaitForReady="COMPLETE">
<ui:Target.TimeoutMS>
<InArgument x:TypeArguments="x:Int32" />
</ui:Target.TimeoutMS>
</ui:Target>
</ui:ExtractData.Target>
</ui:ExtractData>
</ActivityAction>
</ui:BrowserScope.Body>
</ui:BrowserScope>
</ActivityAction>
</ui:OpenBrowser.Body>
</ui:OpenBrowser>
<ui:ForEachRow CurrentIndex="{x:Null}" DataTable="[ExtractDataTable]" DisplayName="For Each Row" sap:VirtualizedContainerService.HintSize="468,492" sap2010:WorkflowViewState.IdRef="ForEachRow_1">
<ui:ForEachRow.Body>
<ActivityAction x:TypeArguments="sd:DataRow">
<ActivityAction.Argument>
<DelegateInArgument x:TypeArguments="sd:DataRow" Name="row" />
</ActivityAction.Argument>
<Sequence DisplayName="Body" sap:VirtualizedContainerService.HintSize="376,344" sap2010:WorkflowViewState.IdRef="Sequence_7">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<ui:NavigateTo Browser="[Browser]" DisplayName="Navigate To" sap:VirtualizedContainerService.HintSize="334,59" sap2010:WorkflowViewState.IdRef="NavigateTo_1" Url="["https://www.bursamalaysia.com" + row("Url").ToString]" />
<Delay Duration="00:00:05" sap:VirtualizedContainerService.HintSize="334,22" sap2010:WorkflowViewState.IdRef="Delay_1" />
<ui:LogMessage DisplayName="Log Message" sap:VirtualizedContainerService.HintSize="334,91" sap2010:WorkflowViewState.IdRef="LogMessage_3" Level="Info" Message="["Here you do all the stuff like Click Annual Report..."]" />
</Sequence>
</ActivityAction>
</ui:ForEachRow.Body>
</ui:ForEachRow>
</Sequence>
</Activity>

Anychart datetime on the y_axis

I am trying to show a trend of processes that run every day over time. Therefore I have a date which I call processing date, which I want to be shown on the X-Axis, and an end_time (date timestamp) since the end time can finish before or after midnight. Therefore I would like to be able to plot the data on the Y axis. I am using Oracle APEX v5, not sure which version of Anychart is running behind, maybe this is version related?
So far, I have not figured out a way for the values returned by my query to be plotted correctly when the values are dates. Is this possible? These are the settings of the y_axis, which when used do not show any data on the graph.
<y_axis >
<scale type="DateTime" mode="Normal" />
<title enabled="false" />
<labels enabled="true" position="Outside">
<font family="Tahoma" size="10" color="0x000000" />
<format>
<![CDATA[{%Value}]]>
</format>
</labels>
<major_grid enabled="False"/>
<minor_grid enabled="False"/>
</y_axis>
When I convert the dates to a number, they are plotted correctly, but so far I had no luck with trying to convert them back to a date using the settings/locale:
<settings>
<locale>
<date_time_format>
<format>%yyyy%MM%dd%HH%mm%ss</format>
</date_time_format>
</locale>
<animation enabled="false"/>
<no_data show_waiting_animation="False">
<label>
<text>#NO_DATA_MESSAGE#</text>
<font family="Verdana" bold="yes" size="10"/>
</label>
</no_data>
</settings>
I am using this to generate the test points with values:
select null as link, trunc (sysdate) as label, to_char((sysdate),'YYYYMMDDHH24MISS') as end_time from dual
union
select null as link, trunc (sysdate)-1 as label, to_char((sysdate)-1,'YYYYMMDDHH24MISS') as end_time from dual
order by label;
The Value of the point ends up being "2016%MM20%HH00%ss", I tried changing the upper/lower case of the formatting to no avail. From the output it looks like the %vars cannot be used concatenated, but if that is the case, then I cannot use values to convert the dates...
Maybe this is conceptually wrong, but so far I have not found a way to plot these correctly. I hope someone can shed some light on this.
Thank you in advance.
Edit:
I managed to do it ignoring the XML from Apex and creating my own datapoints (I will post the complete answer later), this is a sample of the XML:
<?xml version = "1.0" encoding="utf-8" standalone = "yes"?>
<anychart>
<settings>
<animation enabled="false" />
<no_data show_waiting_animation="False">
<label>
<text>No data found</text>
<font family="Verdana" bold="yes" size="10" />
</label>
</no_data>
<locale>
<date_time_format>
<format>
<![CDATA[%dd-%MM-%yyyy %HH:%mm]]>
</format>
</date_time_format>
</locale>
</settings>
<margin left="0" top="0" right="0" bottom="0" />
<charts>
<chart plot_type="CategorizedVertical" name="chart_52322125829114359521">
<chart_settings>
<title enabled="False" />
<chart_background>
<fill type="Solid" color="0xffffff" opacity="0" />
<border enabled="false" />
<corners type="Square" />
</chart_background>
<data_plot_background></data_plot_background>
<axes>
<y_axis>
<scale type="DateTime" mode="Normal" />
<title enabled="false" />
<labels enabled="true" position="Outside">
<font family="Tahoma" size="10" color="0x000000" />
<format>
<![CDATA[{%Value}{dateTimeFormat:%HH:%mm}]]>
</format>
</labels>
<major_grid enabled="True" interlaced="false">
<line color="Black" />
</major_grid>
<minor_grid enabled="True"></minor_grid>
</y_axis>
<x_axis>
<scale type="DateTime" mode="Normal" />
<title enabled="false" />
<labels enabled="true" position="Outside">
<font family="Tahoma" size="10" color="0x000000" />
<format>
<![CDATA[{%Value}{dateTimeFormat:%ddd %dd-%MM-%yyyy}]]>
</format>
</labels>
<major_grid enabled="True" interlaced="false">
<line color="Black" />
</major_grid>
<minor_grid enabled="True"></minor_grid>
</x_axis>
</axes>
<legend enabled="true" position="Right" align="Near" elements_layout="Vertical">
<title enabled="False"/>
<icon>
<marker enabled="true" />
</icon>
<font family="Tahoma" size="10" color="0x000000" />
</legend>
</chart_settings>
<data_plot_settings enable_3d_mode="false" default_series_type="Line">
<line_series>
<tooltip_settings enabled="true">
<format>
<![CDATA[{%SeriesName} {%Name} {%Value}{dateTimeFormat:%HH:%mm}]]>
</format>
<font family="Tahoma" size="10" color="0x000000" />
<position anchor="Center" valign="Top" halign="Center" padding="10" />
</tooltip_settings>
<label_settings enabled='&LABEL.' mode="Outside" multi_line_align="Center">
<format>
<![CDATA[{%Value}{dateTimeFormat:%HH:%mm}]]>
</format>
<background enabled="false" />
<font family="Tahoma" size="10" color="0x000000" />
</label_settings>
<line_style>
<line enabled="true" thickness="2" opacity="1" />
</line_style>
<marker_settings enabled="True" >
<marker type="HLine" />
</marker_settings>
</line_series>
</data_plot_settings>
<data>
<series name="AEG" type="Line">
<point name="01-03-2016 00:00" y="01-01-2001 23:35"></point>
<point name="02-03-2016 00:00" y="01-01-2001 23:16"></point>
<point name="03-03-2016 00:00" y="01-01-2001 23:20"></point>
<point name="04-03-2016 00:00" y="01-01-2001 23:32"></point>
<point name="07-03-2016 00:00" y="01-01-2001 23:28"></point>
<point name="08-03-2016 00:00" y="01-01-2001 23:24"></point>
<point name="09-03-2016 00:00" y="01-01-2001 23:14"></point>
<point name="10-03-2016 00:00" y="01-01-2001 23:30"></point>
<point name="11-03-2016 00:00" y="01-01-2001 23:54"></point>
<point name="14-03-2016 00:00" y="01-01-2001 23:52"></point>
<point name="15-03-2016 00:00" y="01-01-2001 23:27"></point>
<point name="16-03-2016 00:00" y="01-01-2001 23:51"></point>
<point name="17-03-2016 00:00" y="01-01-2001 23:34"></point>
<point name="18-03-2016 00:00" y="01-01-2001 23:32"></point>
<point name="21-03-2016 00:00" y="02-01-2001 00:02"></point>
</series>
</data>
</chart>
</charts>
</anychart>
A new question is, can you help me understand why the tooltip does not get the correct value on the %Name?
<![CDATA[{%SeriesName} {%Name} {%Value}{dateTimeFormat:%HH:%mm}]]>
In the tooltip I am getting the following text on the first point is AEG 01-01-1970 00:00 23:35 and I was expecting, based on the name 01-03-2016 00:00 23:35
Thanks!

How can I get multiple attributes from XML file?

I have an XML file:
<One>
<Document Count="1">
<Customer Id="1" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="13" Name="Test Name"/>
<Passenger Seq="2" Id="14" Name="Test Name4"/>
</Passengers>
</Document>
<Document Count="2">
<Customer Id="2" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="16" Name="Test Name10"/>
<Passenger Seq="2" Id="18" Name="Test Name30"/>
</Passengers>
</Document>
</One>
...
<Two>
<Document Count="1">
<User Id="1" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="123" Name="Test Name"/>
<Passenger Seq="2" Id="124" Name="Test Name2"/>
</Passengers>
</Document>
<Document Count="2">
<Customer Id="2" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="1130" Name="Test Name123"/>
<Passenger Seq="2" Id="1131" Name="Test Name34342"/>
</Passengers>
</Document>
</Two>
My steps:
array = []
doc = Nokogiri::XML(File.open(file.xml))
doc_pass = doc.xpath("//Document//Passengers//Passenger")
doc_pass.each do |pass|
hash = {}
hash[:id] = pass['Name'] #???
array << hash
end
I want to get all attributes like Id, Name from Passengers, and create a hash with all passengers.
Example:
[{ :id => '13', :name => "Test Name"}, { :id => '14', :name => "Test Name4"}, { :id => '16', :name => "Test Name10"}, { :id => '18', :name => "Test Name30"}, { :id => '123', :name => "Test Name"} ... ]
How can I do that?
Just replace the line
hash[:id] = pass['Name'] #???
with
hash[:id] = pass['Id']
hash[:name] = pass['Name']
and it will work, as long as you have a valid XML file.
The XML fragment in your question is not valid for two reasons:
The ... between <One> and <Two> (I guess that's intentional and not a problem with your real data)
Your XML does not have a root element. Currently you have two "roots", the elements <One> and <Two>. If that's how your real XML file is composed, I think Nokogiri will only read the first node.
I'm seeing that you specify the attributes manually in your code. In case you want to get ALL of the attributes in the format you specified, try this:
array = []
Nokogiri::XML(File.open(file.xml)).xpath("//Document//Passengers//Passenger").each do |x|
hash = {}
x.attributes.each do |attribute| # loop through all attributes in the matches found
hash[attribute[1].name.to_sym] = attribute[1].value
end
array << hash
end
array should have this value:
[{:Seq=>"1", :Id=>"13", :Name=>"Test Name"}, {:Seq=>"2", :Id=>"14", :Name=>"Test Name4"}, {:Seq=>"1", :Id=>"16", :Name=>"Test Name10"}, {:Seq=>"2", :Id=>"18", :Name=>"Test Name30"}]
I'd do it like this:
require 'nokogiri'
doc = Nokogiri::XML(<<EOT)
<xml>
<One>
<Document Count="1">
<Customer Id="1" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="13" Name="Test Name"/>
<Passenger Seq="2" Id="14" Name="Test Name4"/>
</Passengers>
</Document>
<Document Count="2">
<Customer Id="2" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="16" Name="Test Name10"/>
<Passenger Seq="2" Id="18" Name="Test Name30"/>
</Passengers>
</Document>
</One>
<Two>
<Document Count="1">
<User Id="1" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="123" Name="Test Name"/>
<Passenger Seq="2" Id="124" Name="Test Name2"/>
</Passengers>
</Document>
<Document Count="2">
<Customer Id="2" Type="0"/>
<Passengers>
<Passenger Seq="1" Id="1130" Name="Test Name123"/>
<Passenger Seq="2" Id="1131" Name="Test Name34342"/>
</Passengers>
</Document>
</Two>
</xml>
EOT
Here's how to find all <Passenger> nodes and grab their data:
array = doc.search('Passenger').map{ |node|
{
id: node['Id'],
name: node['Name']
}
}
Here's what array looks like:
array
# => [{:id=>"13", :name=>"Test Name"},
# {:id=>"14", :name=>"Test Name4"},
# {:id=>"16", :name=>"Test Name10"},
# {:id=>"18", :name=>"Test Name30"},
# {:id=>"123", :name=>"Test Name"},
# {:id=>"124", :name=>"Test Name2"},
# {:id=>"1130", :name=>"Test Name123"},
# {:id=>"1131", :name=>"Test Name34342"}]
I'm using a CSS selector. Because I wanted all the "Passenger" nodes, then search becomes easy and doesn't require drilling down through the chain of parent nodes.
An array of hashes is awkward to use/reuse though. I'd recommend using a regular hash if there is no chance of collisions in :id:
hash = doc.search('Passenger').map{ |node| [node['Id'], node['Name']] }.to_h
hash
# => {"13"=>"Test Name",
# "14"=>"Test Name4",
# "16"=>"Test Name10",
# "18"=>"Test Name30",
# "123"=>"Test Name",
# "124"=>"Test Name2",
# "1130"=>"Test Name123",
# "1131"=>"Test Name34342"}
If you need to dynamically track all the parameters for Passenger nodes, whenever new ones are added or old ones deleted:
hash = doc.search('Passenger').map{ |node|
[
node['Id'],
node.attribute_nodes.map{ |a|
[a.name, a.value]
}.to_h
]
}.to_h
hash
# => {"13"=>{"Seq"=>"1", "Id"=>"13", "Name"=>"Test Name"},
# "14"=>{"Seq"=>"2", "Id"=>"14", "Name"=>"Test Name4"},
# "16"=>{"Seq"=>"1", "Id"=>"16", "Name"=>"Test Name10"},
# "18"=>{"Seq"=>"2", "Id"=>"18", "Name"=>"Test Name30"},
# "123"=>{"Seq"=>"1", "Id"=>"123", "Name"=>"Test Name"},
# "124"=>{"Seq"=>"2", "Id"=>"124", "Name"=>"Test Name2"},
# "1130"=>{"Seq"=>"1", "Id"=>"1130", "Name"=>"Test Name123"},
# "1131"=>{"Seq"=>"2", "Id"=>"1131", "Name"=>"Test Name34342"}}
Basically that'll create a hash representation of the node, which can be good or bad, depending on what you're trying to do with the data.

Resources