Reputation: 393
I'm trying to create an XML simple object but I keep getting errors about undefined domains. All the examples i've seen have some type of URL defined in the XML file but the XML I receive from an CURL call doesn't have those URLs so i'm not entirely certain what to do.
<?xml version="1.0" encoding="UTF-8" ?>
<Items>
<Item>
<ActivityName>Faculty Lecture</ActivityName>
<ParentActivityName>Faculty Lecture</ParentActivityName>
<Description></Description>
<StartDate>2/1/2017 12:00:00 AM</StartDate>
<EndDate>2/1/2017 12:00:00 AM</EndDate>
<StartMinute>990</StartMinute>
<EndMinute>1080</EndMinute>
<CampusName>MAIN</CampusName>
<BuildingCode>LIB</BuildingCode>
<RoomNumber>105</RoomNumber>
<RoomName>News Events Room</RoomName>
<Customer:EventMeetingByActivityId.Event.Customer.Name>Library</Customer:EventMeetingByActivityId.Event.Customer.Name>
<ContactFirstName:EventMeetingByActivityId.Event.PrimaryCustomerContact.Person.FirstName>Jane</ContactFirstName:EventMeetingByActivityId.Event.PrimaryCustomerContact.Person.FirstName>
<ContactLastName:EventMeetingByActivityId.Event.PrimaryCustomerContact.Person.LastName>Doe</ContactLastName:EventMeetingByActivityId.Event.PrimaryCustomerContact.Person.LastName>
<MeetingType:EventMeetingByActivityId.EventMeetingType.Name>Meeting</MeetingType:EventMeetingByActivityId.EventMeetingType.Name>
</Item>
</Items>
Here is the code that is throwing the warning.
$data = simplexml_load_string($result);
$data->registerXPathNamespace('Customer', 'https://www.aaiscloud.com/');
$data->registerXPathNamespace('ContactFirstName', 'https://www.aaiscloud.com/');
$data->registerXPathNamespace('ContactLastName', 'https://www.aaiscloud.com/');
$data->registerXPathNamespace('MeetingType', 'https://www.aaiscloud.com/');
if I edit the $result and remove the domains then the warning goes away but i'm not sure if this is a smart thing to do.
Upvotes: 0
Views: 145
Reputation: 111601
Any namespace prefix (eg Customer
) used in an XML document must be declared in that XML document.
Change
<Items>
to
<Items xmlns:Customer="https://www.aaiscloud.com/">
Also add all similar declarations for other namespace prefixes used in the XML. BTW, it is customary, although not required, to use short lower-case abbreviations for namespace prefixes -- you might want to switch from Customer
to c
, cust
, or customer
.
Upvotes: 1