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 7874585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:50:04+00:00 2026-06-03T02:50:04+00:00

I’m stumped. I have the following XML in a file: <?xml version=1.0 encoding=UTF-8?> <grant:GrantApplication

  • 0

I’m stumped. I have the following XML in a file:

<?xml version="1.0" encoding="UTF-8"?>
<grant:GrantApplication xmlns:grant="http://apply.grants.gov/system/MetaGrantApplication" xmlns:globLib="http://apply.grants.gov/system/GlobalLibrary-V1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://apply.grants.gov/system/MetaGrantApplication http://apply07.grants.gov/apply/opportunities/schemas/agency/oppEPA-R5-GL2011-1-cfda66.469.xsd">
    <grant:Forms>
        <EPA_KeyContacts:KeyContactPersons xmlns:EPA_KeyContacts="http://apply.grants.gov/forms/EPA_KeyContacts-V1.1" EPA_KeyContacts:FormVersion="1.1">
            <EPA_KeyContacts:AuthorizedRepresentative>
                <globLib:Name xmlns:globLib="http://apply.grants.gov/system/GlobalLibrary-V2.0">
                    <globLib:FirstName>Jane</globLib:FirstName>
                    <globLib:LastName>Doe</globLib:LastName>
                </globLib:Name>
            </EPA_KeyContacts:AuthorizedRepresentative>
        </EPA_KeyContacts:KeyContactPersons>
        <EPA4700_4_2_0:EPA4700_4_2_0 xmlns:EPA4700_4_2_0="http://apply.grants.gov/forms/EPA4700_4_2_0-V2.0" EPA4700_4_2_0:FormVersion="2.0">
            <EPA4700_4_2_0:ApplicantInfo>
                <EPA4700_4_2_0:ApplicantName>ABC 123</EPA4700_4_2_0:ApplicantName>
                <EPA4700_4_2_0:ApplicantAddress>
                    <EPA4700_4_2_0:Address>123 Street</EPA4700_4_2_0:Address>
                    <EPA4700_4_2_0:City>Buffalo</EPA4700_4_2_0:City>
                    <EPA4700_4_2_0:State>NY: New York</EPA4700_4_2_0:State>
                    <EPA4700_4_2_0:ZipCode>12345</EPA4700_4_2_0:ZipCode>
                </EPA4700_4_2_0:ApplicantAddress>
            <EPA4700_4_2_0:ApplicantInfo>
        <EPA4700_4_2_0:EPA4700_4_2_0 xmlns:EPA4700_4_2_0="http://apply.grants.gov/forms/EPA4700_4_2_0-V2.0" EPA4700_4_2_0:FormVersion="2.0">
        <SF424_2_1:SF424_2_1 xmlns:SF424_2_1="http://apply.grants.gov/forms/SF424_2_1-V2.1" SF424_2_1:FormVersion="2.1">
            <SF424_2_1:ContactPerson>
                <globLib:FirstName xmlns:globLib="http://apply.grants.gov/system/GlobalLibrary-V2.0">Jane</globLib:FirstName>
                <globLib:LastName xmlns:globLib="http://apply.grants.gov/system/GlobalLibrary-V2.0">Doe</globLib:LastName>
            <SF424_2_1:ContactPerson>
        <SF424_2_1:SF424_2_1>
    </grant:Forms>
</grant:GrantApplication>

Using SimpleXML in PHP, I have the following code:

$xml = simplexml_load_file($appdir);

$xml->registerXPathNamespace("grant","http://apply.grants.gov/system/MetaGrantApplication");
$xml->registerXPathNamespace("header","http://apply.grants.gov/system/Header-V1.0");
$xml->registerXPathNamespace("globLib","http://apply.grants.gov/system/GlobalLibrary-V2.0");
$xml->registerXPathNamespace("EPA_KeyContacts","http://apply.grants.gov/forms/EPA_KeyContacts-V1.1");
$xml->registerXPathNamespace("SF424A","http://apply.grants.gov/forms/SF424A-V1.0");
$xml->registerXPathNamespace("SF424_2_1","http://apply.grants.gov/forms/SF424_2_1-V2.1");
$xml->registerXPathNamespace("EPA4700_4_2_0","http://apply.grants.gov/forms/EPA4700_4_2_0-V2.0");

$rawContactFirstName = $xml->xpath("/grant:GrantApplication/grant:Forms/SF424_2_1:SF424_2_1/SF424_2_1:ContactPerson/globLib:FirstName");
$contactFirstName = $rawContactFirstName[0];

$rawContactLastName = $xml->xpath("/grant:GrantApplication/grant:Forms/EPA_KeyContacts:KeyContactPersons/EPA_KeyContacts:AuthorizedRepresentative/globLib:Name/globLib:LastName");
$contactLastName = $rawContactLastName[0];

$rawStreetAddress = $xml->xpath("/grant:GrantApplication/grant:Forms/EPA4700_4_2_0:EPA4700_4_2_0/EPA4700_4_2_0:ApplicantInfo/EPA4700_4_2_0:ApplicantAddress/EPA4700_4_2_0:Address");
$streetAddress = $rawStreetAddress[0];

$rawCity = $xml->xpath("/grant:GrantApplication/grant:Forms/EPA4700_4_2_0:EPA4700_4_2_0/EPA4700_4_2_0:ApplicantInfo/EPA4700_4_2_0:ApplicantAddress/EPA4700_4_2_0:City");
$city = $rawCity[0];

$rawState = $xml->xpath("/grant:GrantApplication/grant:Forms/EPA4700_4_2_0:EPA4700_4_2_0/EPA4700_4_2_0:ApplicantInfo/EPA4700_4_2_0:ApplicantAddress/EPA4700_4_2_0:State");
$state = $rawState[0];

$rawZip = $xml->xpath("/grant:GrantApplication/grant:Forms/EPA4700_4_2_0:EPA4700_4_2_0/EPA4700_4_2_0:ApplicantInfo/EPA4700_4_2_0:ApplicantAddress/EPA4700_4_2_0:ZipCode");
$zip = $rawZip[0];

echo $contactFirstName."<br>".
     $contactLastName."<br>".
     $streetAddress."<br>".
     $city."<br>".
     $state."<br>".
     $zip."<br>";

I get the following output:

Notice: Undefined offset: 0 in file.php on line 105 Notice: Undefined
offset: 0 in file.php on line 108

123 Street

Buffalo

NY: New York

12345

Line 105 referencing $rawContactFirstName[0] and Line 108 referencing $rawContactLastName[0]

The first and last name is in the document twice and I’m referencing last name from the first occurrence and first name from the second occurrence because of the difference in the way that the globLib namespace is referenced.

I cannot get any information from any of the elements using the globLib namespace and I don’t understand why. I can get any other piece of information from the document as long as it’s not using the globLib namespace.

$xml->xpath(); should return an array. Consider the following:

print_r($rawContactFirstName);

Output:
Array ( )

var_dump($rawContactFirstName);
var_dump($rawContactFirstName[0]);

Output:
array(0) { }

I don’t understand how all of the other namespaces can return data without issue except this one using the exact same technique. According to http://validator.w3.org/ the XML document is valid.

Any ideas?

  • 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-03T02:50:06+00:00Added an answer on June 3, 2026 at 2:50 am

    Try changing this line:

    $xml->registerXPathNamespace("globLib","http://apply.grants.gov/system/GlobalLibrary-V2.0");
    

    to:

    $xml->registerXPathNamespace("globLib2","http://apply.grants.gov/system/GlobalLibrary-V2.0");
    

    (or whatever unique prefix you’d like to use).

    And then reference it as such in your xpath:

    $rawContactFirstName = $xml->xpath("/grant:GrantApplication/grant:Forms/SF424_2_1:SF424_2_1/SF424_2_1:ContactPerson/globLib2:FirstName");
    

    I think what’s happening is that that the prefix “globLib” is already registered with a different URI in the document element, and that’s somehow confusing registerXPathNamespace.

    As a side note, the XML you posted doesn’t appear to be valid. It’s got a bunch of unclosed tags and tags that are “closed” with opening tags – so I’d also make absolutely sure that whatever XML you’re using is valid.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.