0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The $results(the xml file) is what is retrieved from an outside company. Does this mean i have to manipulate the string before simplexml_load_string ?
If you're being provided with "XML" that uses undeclared namespace prefixes, then you're not being provided with XML at all. Tell the provider to fix their data. If that's not possible, you'll have to repair the data (manually or by treating the textual object as text, not XML, because it isn't XML) as shown above before you can use any conformant XML tools or libraries on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.