Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:58:05+00:00 2026-06-15T10:58:05+00:00

Possible Duplicate: Nokogiri/Xpath namespace query I have an XML file like this: <?xml version=1.0

  • 0

Possible Duplicate:
Nokogiri/Xpath namespace query

I have an XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
<Structure xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message" xmlns:Structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure SDMXMessage.xsd">
  <Header>
    <ID>001-0001</ID>
    <Test>true</Test>
    <Name xml:lang="en">Producer deliveries of major grains, Canada and selected provinces</Name>
    <Name xml:lang="fr">Livraisons des producteurs des principaux grains, Canada et certaines provinces</Name>
    <Prepared>2012-11-22T18:42:35-05:00</Prepared>
    <Sender id="STATCAN" />
    <Receiver id="STATCAN" />
  </Header>
  <CodeLists>
    <structure:CodeList xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" id="GEO" agencyID="STATCAN" version="1.0" isFinal="false">
      <structure:Name xml:lang="en">Geography</structure:Name>
      <structure:Name xml:lang="fr">Géographie</structure:Name>
      <structure:Code value="7">
        <structure:Description xml:lang="en">Canada</structure:Description>
        <structure:Description xml:lang="fr">Canada</structure:Description>
      </structure:Code>
      <structure:Code value="8">
        <structure:Description xml:lang="en">Eastern Canada</structure:Description>
        <structure:Description xml:lang="fr">L'Est du Canada</structure:Description>
      </structure:Code>
      <structure:Code value="9">
        <structure:Description xml:lang="en">Quebec</structure:Description>
        <structure:Description xml:lang="fr">Québec</structure:Description>
      </structure:Code>
      <structure:Code value="10">
        <structure:Description xml:lang="en">Ontario</structure:Description>
        <structure:Description xml:lang="fr">Ontario</structure:Description>
      </structure:Code>
      <structure:Code value="3">
        <structure:Description xml:lang="en">Western Canada</structure:Description>
        <structure:Description xml:lang="fr">L'Ouest du Canada</structure:Description>
      </structure:Code>
      <structure:Code value="2">
        <structure:Description xml:lang="en">Prairie provinces</structure:Description>
        <structure:Description xml:lang="fr">Provinces des Prairies</structure:Description>
      </structure:Code>
      <structure:Code value="4">
        <structure:Description xml:lang="en">Manitoba</structure:Description>
        <structure:Description xml:lang="fr">Manitoba</structure:Description>
      </structure:Code>
      <structure:Code value="5">
        <structure:Description xml:lang="en">Saskatchewan</structure:Description>
        <structure:Description xml:lang="fr">Saskatchewan</structure:Description>
      </structure:Code>
      <structure:Code value="6">
        <structure:Description xml:lang="en">Alberta</structure:Description>
        <structure:Description xml:lang="fr">Alberta</structure:Description>
      </structure:Code>
      <structure:Code value="1">
        <structure:Description xml:lang="en">British Columbia</structure:Description>
        <structure:Description xml:lang="fr">Colombie-Britannique</structure:Description>
      </structure:Code>
    </structure:CodeList>
    <structure:CodeList xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" id="TYP" agencyID="STATCAN" version="1.0" isFinal="false">
      <structure:Name xml:lang="en">Type of grain</structure:Name>
      <structure:Name xml:lang="fr">Type de céréales</structure:Name>
      <structure:Code value="1">
        <structure:Description xml:lang="en">All grains, total</structure:Description>
        <structure:Description xml:lang="fr">Céréales, totaux</structure:Description>
      </structure:Code>
      <structure:Code value="2">
        <structure:Description xml:lang="en">Wheat, total</structure:Description>
        <structure:Description xml:lang="fr">Blé, total</structure:Description>
      </structure:Code>
      <structure:Code value="3">
        <structure:Description xml:lang="en">Wheat, excluding durum</structure:Description>
        <structure:Description xml:lang="fr">Blé (sauf le blé dur)</structure:Description>
      </structure:Code>
      <structure:Code value="4">
        <structure:Description xml:lang="en">Durum wheat</structure:Description>
        <structure:Description xml:lang="fr">Blé dur</structure:Description>
      </structure:Code>
      <structure:Code value="5">
        <structure:Description xml:lang="en">Oats</structure:Description>
        <structure:Description xml:lang="fr">Avoine</structure:Description>
      </structure:Code>
      <structure:Code value="6">
        <structure:Description xml:lang="en">Barley</structure:Description>
        <structure:Description xml:lang="fr">Orge</structure:Description>
      </structure:Code>
      <structure:Code value="7">
        <structure:Description xml:lang="en">Rye</structure:Description>
        <structure:Description xml:lang="fr">Seigle</structure:Description>
      </structure:Code>
      <structure:Code value="8">
        <structure:Description xml:lang="en">Flaxseed</structure:Description>
        <structure:Description xml:lang="fr">Lin</structure:Description>
      </structure:Code>
      <structure:Code value="9">
        <structure:Description xml:lang="en">Canola (rapeseed)</structure:Description>
        <structure:Description xml:lang="fr">Canola (colza)</structure:Description>
      </structure:Code>
    </structure:CodeList>
  </CodeLists>
  <Concepts>
    <structure:Concept xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" />
  </Concepts>
  <KeyFamilies>
    <structure:KeyFamily xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" version="1.0" isFinal="false">
      <structure:Components>
        <structure:Dimension codelist="GEO" />
        <structure:Dimension codelist="TYP" />
        <structure:TimeDimension conceptRef="TIME_PERIOD" />
        <structure:PrimaryMeasure conceptRef="OBS_VALUE" />
      </structure:Components>
    </structure:KeyFamily>
  </KeyFamilies>
</Structure>

How can I extract different CodeLists and their associated Name and Description from this using Nokogiri? I can get the values of Name, Sender, Receiver of the Header element, but, can’t get the values inside the CodeList blocks because of that structure: keyword in the start of each element.

Could anybody please help on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:58:06+00:00Added an answer on June 15, 2026 at 10:58 am

    If you’re using XPath, you should provide a prefix for these elements. Following are some possible queries:

    ns = {"structure" => "http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure"}
    doc.xpath("//structure:CodeList", ns)
    doc.xpath("//structure:CodeList/structure:Name", ns)
    doc.xpath("//structure:CodeList/structure:Code/structure:Description", ns)
    

    To get the prefix “structure” to work, you need to let Nokogiri know about the mapping between the prefix and the URI it refers to by passing a hash as the second argument.

    EDIT: Updated per the comments to use namespaces properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Nokogiri/Xpath namespace query Suppose there is XML <?xml version=1.0 encoding=utf-8?> <SomeResponse xmlns=some_namespace>
Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: Parsing XML String in C# How to process the below XML file
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: how to delete a file? My application first reads the fields in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.