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

  • SEARCH
  • Home
  • 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 9191661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:44:20+00:00 2026-06-17T20:44:20+00:00

I have an XML Structure, like I have outline below. I am trying to

  • 0

I have an XML Structure, like I have outline below. I am trying to use xPath to find particular elements within the structure, but have been unsuccessful. This is what I have thus far:

$resultset[0][‘bibXML’] – Here is a paste of exactly what is being passed in this variable. http://pastebin.com/CwtFG5dj

Here is a link to the output of the $myNode using print_r().
http://pastebin.com/TwDaxs42

$myNode = new SimpleXMLElement($resultset[0]['bibXML']);
$bnum = $myNode->xpath("record/datafield[@tag='035']/subfield[@code='a']");


<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns="http://www.loc.gov/MARC21/slim">
<record>
    <leader>01220nam  2200265   4500</leader>
    <controlfield tag="001">ocm00000197</controlfield>
    <datafield tag="035" ind1="" ind2="">
        <subfield code="a">.b10000021</subfield>
        <subfield code="b">a    </subfield>
        <subfield code="c">-</subfield>
    </datafield>
    <datafield tag="245" ind1="" ind2="">
        <subfield code="a">Some Book Title</subfield>
        <subfield code="b">a    </subfield>
        <subfield code="c">-</subfield>
    </datafield>
</record>
</collection>
  • 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-17T20:44:21+00:00Added an answer on June 17, 2026 at 8:44 pm

    Your elements are in the http://www.loc.gov/MARC21/slim namespace. Learn about xml namespaces.

    Your XPath is matching elements in the null namespace because they are not prefixed. Since your elements are not actually in the null namespace, your XPath does not match anything.

    You need to register a namespace prefix with the registerXPathNamespace method and then use that prefix to qualify your element names.

    This would be your complete code:

    $myNode = simplexml_load_string($resultset[0]['bibXML']);
    
    $myNode->registerXPathNamespace('m21s', 'http://www.loc.gov/MARC21/slim');
    
    $results = $myNode->xpath('m21s:record/m21s:datafield[@tag="035"]/m21s:subfield[@code="a"]');
    $bnum = ($results) ? (string) $results[0] : null;
    
    var_export($bnum);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML-structure. Context of executing XPath is one of the elements with class
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five
I have an XML structure that looks like: <Succeeded p1:type=Edm.Boolean xmlns:p1=http://schemas.microsoft.com/ado/2007/08/dataservices/metadata xmlns=http://schemas.microsoft.com/ado/2007/08/dataservices>false</Succeeded> Since I
I have a directory structure that looks like this: /a/f.xml /b/f.xml /c/f.xml /d/f.xml What
I have a xml structure like this: <root> <acteCourantPHP> <acCLibel>Soins Semestre 6</acCLibel> <acCDeb>2011-12-05</acCDeb> <acCFin>2012-06-05</acCFin>
I have an XML structure like the following: <Root> <Base> <Greeting>Base Hello!</Greeting> <SpecialMessage>Base Special
If I have an xml structure like this <root> <sub> <node /> <node />
I have an XML doc with a structure like this: <Book> <Title title=Door Three/>
I have an xml document that has a structure like so: <?xml version=1.0 encoding=iso-8859-1
I have an XML structure that looks like this: <root> <index> <item>item 1</item> <item>item

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.