Jump to content

Problems accessing nodes after using simplexml_load_file


kellendil
Go to solution Solved by boompa,

Recommended Posts

Hi!

I'm having trouble accessing data with simpleXML_load_file

 

I have a working script that loads an XML-file and outputs in a proprietary format that I've written, but for some reason I can't get it to work with this second set of XML-files.

 

Loading the file seems to work fine. I load the file into a variable, and can print the contents of the file using echo $xml -> asXML();

 

However, when I try to access a single node using: 

echo $xml->{'SOAP-ENV:Envelope'}->{'SOAP-ENV:Body'}->Order->OrderHeader->OrderNumber->BuyerOrderNumber;

I get the following error:

Notice: Trying to get property of non-object in C:\www\convert_uio.php on line 28

 

XML-file looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<SOAP-ENV:Header>
		<nseps:endpoints SOAP-ENV:mustUnderstand="true" xmlns:nseps="urn:schemas-IBX:/docs/endpoint.nsendpoint">
			<nseps:to>
				<nseps:address>8b51fc8c-7aba-1000-bbbe-c0a878330001</nseps:address>
			</nseps:to>
			<nseps:from>
				<nseps:address>1b0ad9d6-7a05-1000-a43c-c0a878330001</nseps:address>
			</nseps:from>
		</nseps:endpoints>
		<nsprop:properties SOAP-ENV:mustUnderstand="true" xmlns:nsprop="urn:schemas-IBX:/docs/property.nsproperty">
			<nsprop:identity>fb1797dbb1f14a179482b1bb53bc7c14</nsprop:identity>
			<nsprop:sentAt>2014-09-02T00:00:00+01:00</nsprop:sentAt>
			<nsprop:topic>Order</nsprop:topic>
		</nsprop:properties>
	</SOAP-ENV:Header>
	<SOAP-ENV:Body> 
		<Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd"> 
			<OrderHeader> 
				<OrderNumber> 
					<BuyerOrderNumber>E14124673</BuyerOrderNumber> 
				</OrderNumber> 
				<OrderIssueDate>20140902T00:00:00+01:00</OrderIssueDate>
				<OrderReferences>
					<AccountCode>
						<Reference>
							<RefNum>no_unoslo</RefNum>
						</Reference>
					</AccountCode>
				</OrderReferences>
				<Purpose>
					<PurposeCoded>Original</PurposeCoded>
				</Purpose>
				<RequestedResponse>
					<RequestedResponseCoded>NoAcknowledgementNeeded</RequestedResponseCoded>
				</RequestedResponse>
				<OrderType>
					<OrderTypeCoded>PurchaseOrder</OrderTypeCoded>
				</OrderType>
				<OrderCurrency>
					<Currency>
						<CurrencyCoded>NOK</CurrencyCoded>
					</Currency>
				</OrderCurrency>
				<OrderLanguage>
					<Language LanguageDependent="false">
						<LanguageCoded>no</LanguageCoded>
					</Language>
				</OrderLanguage>
				<OrderDates>
					<RequestedDeliverByDate>20140904T00:00:00+01:00</RequestedDeliverByDate>
				</OrderDates>
				<OrderParty>
					<BuyerParty>
						<Party>
							<PartyID>
								<Identifier>
									<Agency>
										<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
									</Agency>
									<Ident>no_uio</Ident>
								</Identifier>
							</PartyID>
							<NameAddress>
								<Name1>xxxxxxxxxxxxx</Name1>
								<Name2>xxxxxxxxxxxxx</Name2>
								<POBox>xxxxx</POBox>
								<PostalCode>NO-0316</PostalCode>
								<City>Oslo</City>
								<Country>
									<CountryCoded>NO</CountryCoded>
								</Country>
							</NameAddress>
							<OrderContact>
								<Contact>
									<ContactName>Some Name</ContactName>
									<ContactFunction>
										<ContactFunctionCoded>PurchasingContact</ContactFunctionCoded>
									</ContactFunction>
									<ListOfContactNumber>
										<ContactNumber>
											<ContactNumberValue>email@email.no</ContactNumberValue>
											<ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
										</ContactNumber>
										<ContactNumber>
											<ContactNumberValue>+4700000000</ContactNumberValue>
											<ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
										</ContactNumber>
									</ListOfContactNumber>
								</Contact>
							</OrderContact>
						</Party>
					</BuyerParty>
					<BuyerTaxInformation>
						<PartyTaxInformation>
							<TaxIdentifier>
								<Identifier>
									<Agency>
										<AgencyCoded>Other</AgencyCoded>
										<AgencyCodedOther>VAT Number</AgencyCodedOther>
									</Agency>
									<Ident>00000000</Ident>
								</Identifier>
							</TaxIdentifier>
						</PartyTaxInformation>
					</BuyerTaxInformation>
					<SellerParty>
						<Party>
							<PartyID>
								<Identifier>
									<Agency>
										<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
									</Agency>
									<Ident>8b51fc8c-7aba-1000-bbbe-c0a878330001</Ident>
								</Identifier>
							</PartyID>
							<NameAddress>
								<Name1>Name 2</Name1>
								<Street>Adress</Street>
								<PostalCode> 0314</PostalCode>
								<City>OSLO</City>
								<Country>
									<CountryCoded>NO</CountryCoded>
								</Country>
							</NameAddress>
							<OrderContact>
								<Contact>
									<ContactName>N/A</ContactName>
									<ListOfContactNumber>
										<ContactNumber>
											<ContactNumberValue>email</ContactNumberValue>
											<ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
										</ContactNumber>
										<ContactNumber>
											<ContactNumberValue>47 0000000</ContactNumberValue>
											<ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded>
										</ContactNumber>
									</ListOfContactNumber>
								</Contact>
							</OrderContact>
						</Party>
					</SellerParty>
					<ShipToParty>
						<Party>
							<PartyID>
								<Identifier>
									<Agency>
										<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
									</Agency>
									<Ident />
								</Identifier>
							</PartyID>
							<NameAddress>
								<Name1>Name</Name1>
								<Name2>Name2 </Name2>
								<Street>Adress</Street>
								<StreetSupplement1>0318 Oslo</StreetSupplement1>
								<PostalCode>NO-0562</PostalCode>
								<City>OSLO</City>
								<Country>
									<CountryCoded>NO</CountryCoded>
								</Country>
							</NameAddress>
							<OrderContact>
								<Contact>
									<ContactName>Name</ContactName>
									<ContactFunction>
										<ContactFunctionCoded>PurchasingContact</ContactFunctionCoded>
									</ContactFunction>
									<ListOfContactNumber>
										<ContactNumber>
											<ContactNumberValue>emamil</ContactNumberValue>
											<ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
										</ContactNumber>
										<ContactNumber>
											<ContactNumberValue>+470000000</ContactNumberValue>
											<ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
										</ContactNumber>
									</ListOfContactNumber>
								</Contact>
							</OrderContact>
							<ReceivingContact>
								<Contact>
									<ContactName>Name</ContactName>
									<ContactFunction>
										<ContactFunctionCoded>PurchasingContact</ContactFunctionCoded>
									</ContactFunction>
									<ListOfContactNumber>
										<ContactNumber>
											<ContactNumberValue>email</ContactNumberValue>
											<ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
										</ContactNumber>
										<ContactNumber>
											<ContactNumberValue>+4700000000</ContactNumberValue>
											<ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
										</ContactNumber>
									</ListOfContactNumber>
								</Contact>
							</ReceivingContact>
						</Party>
					</ShipToParty>
					<BillToParty>
						<Party>
							<PartyID>
								<Identifier>
									<Agency>
										<AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded>
									</Agency>
									<Ident>no_uio</Ident>
								</Identifier>
							</PartyID>
							<NameAddress>
								<Name1>Name</Name1>
								<Name2>Adress</Name2>
								<POBox>adress2</POBox>
								<PostalCode>NO-0316</PostalCode>
								<City>Oslo</City>
								<County />
								<District>9908:971035854</District>
								<Country>
									<CountryCoded>NO</CountryCoded>
								</Country>
							</NameAddress>
							<OrderContact>
								<Contact>
									<ContactName>Name</ContactName>
									<ContactFunction>
										<ContactFunctionCoded>PurchasingContact</ContactFunctionCoded>
									</ContactFunction>
									<ListOfContactNumber>
										<ContactNumber>
											<ContactNumberValue>email</ContactNumberValue>
											<ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
										</ContactNumber>
										<ContactNumber>
											<ContactNumberValue>+470000000</ContactNumberValue>
											<ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
										</ContactNumber>
									</ListOfContactNumber>
								</Contact>
							</OrderContact>
						</Party>
					</BillToParty>
				</OrderParty>
				<OrderTermsOfDelivery>
					<TermsOfDelivery>
						<TermsOfDeliveryFunctionCoded>Other</TermsOfDeliveryFunctionCoded>
						<TermsOfDeliveryFunctionCodedOther>Other</TermsOfDeliveryFunctionCodedOther>
						<TransportTermsCoded>Other</TransportTermsCoded>
						<TransportTermsCodedOther>DDP</TransportTermsCodedOther>
						<ShipmentMethodOfPaymentCoded>Other</ShipmentMethodOfPaymentCoded>
						<ShipmentMethodOfPaymentCodedOther>Other</ShipmentMethodOfPaymentCodedOther>
						<TransportDescription />
					</TermsOfDelivery>
				</OrderTermsOfDelivery>
				<OrderHeaderNote />
			</OrderHeader>
			<OrderDetail>
				<ListOfItemDetail>
					<ItemDetail>
						<BaseItemDetail>
							<LineItemNum>
								<BuyerLineItemNum>1</BuyerLineItemNum>
							</LineItemNum>
							<LineItemType>
								<LineItemTypeCoded>Item</LineItemTypeCoded>
							</LineItemType>
							<ItemIdentifiers>
								<PartNumbers>
									<SellerPartNumber>
										<PartNum>
											<PartID>1000000000001</PartID>
										</PartNum>
									</SellerPartNumber>
									<ManufacturerPartNumber>
										<PartID />
									</ManufacturerPartNumber>
								</PartNumbers>
								<ItemDescription>Normal frakt, pris 20 NOK</ItemDescription>
							</ItemIdentifiers>
							<TotalQuantity>
								<Quantity>
									<QuantityValue>1</QuantityValue>
									<UnitOfMeasurement>
										<UOMCoded>EA</UOMCoded>
									</UnitOfMeasurement>
								</Quantity>
							</TotalQuantity>
							<OffCatalogFlag>false</OffCatalogFlag>
						</BaseItemDetail>
						<PricingDetail>
							<ListOfPrice>
								<Price>
									<UnitPrice>
										<UnitPriceValue>20</UnitPriceValue>
										<Currency>
											<CurrencyCoded>NOK</CurrencyCoded>
										</Currency>
										<UnitOfMeasurement>
											<UOMCoded>EA</UOMCoded>
										</UnitOfMeasurement>
									</UnitPrice>
									<PriceBasisQuantity>
										<Quantity>
											<QuantityValue>1</QuantityValue>
											<UnitOfMeasurement>
												<UOMCoded>EA</UOMCoded>
											</UnitOfMeasurement>
										</Quantity>
									</PriceBasisQuantity>
								</Price>
							</ListOfPrice>
							<Tax>
								<TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded>
								<TaxCategoryCoded>StandardRate</TaxCategoryCoded>
								<TaxTypeCoded>ValueAddedTax</TaxTypeCoded>
								<TaxPercent>.00</TaxPercent>
								<TaxableAmount>20.00</TaxableAmount>
								<TaxAmount>.00</TaxAmount>
							</Tax>
							<TotalValue>
								<MonetaryValue>
									<MonetaryAmount>20.00</MonetaryAmount>
								</MonetaryValue>
							</TotalValue>
						</PricingDetail>
						<DeliveryDetail>
							<ListOfScheduleLine>
								<ScheduleLine>
									<Quantity>
										<QuantityValue>1</QuantityValue>
										<UnitOfMeasurement>
											<UOMCoded>EA</UOMCoded>
										</UnitOfMeasurement>
									</Quantity>
									<RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate>
								</ScheduleLine>
							</ListOfScheduleLine>
						</DeliveryDetail>
					</ItemDetail>
					<ItemDetail>
						<BaseItemDetail>
							<LineItemNum>
								<BuyerLineItemNum>2</BuyerLineItemNum>
							</LineItemNum>
							<LineItemType>
								<LineItemTypeCoded>Item</LineItemTypeCoded>
							</LineItemType>
							<ItemIdentifiers>
								<PartNumbers>
									<SellerPartNumber>
										<PartNum>
											<PartID>9788258312007</PartID>
										</PartNum>
									</SellerPartNumber>
									<ManufacturerPartNumber>
										<PartID />
									</ManufacturerPartNumber>
								</PartNumbers>
								<ItemDescription>Hovedtariffavtalen i staten 1. mai 2014 - 30. april 2016 (p.100kr)</ItemDescription>
							</ItemIdentifiers>
							<TotalQuantity>
								<Quantity>
									<QuantityValue>2</QuantityValue>
									<UnitOfMeasurement>
										<UOMCoded>EA</UOMCoded>
									</UnitOfMeasurement>
								</Quantity>
							</TotalQuantity>
							<OffCatalogFlag>false</OffCatalogFlag>
						</BaseItemDetail>
						<PricingDetail>
							<ListOfPrice>
								<Price>
									<UnitPrice>
										<UnitPriceValue>100</UnitPriceValue>
										<Currency>
											<CurrencyCoded>NOK</CurrencyCoded>
										</Currency>
										<UnitOfMeasurement>
											<UOMCoded>EA</UOMCoded>
										</UnitOfMeasurement>
									</UnitPrice>
									<PriceBasisQuantity>
										<Quantity>
											<QuantityValue>1</QuantityValue>
											<UnitOfMeasurement>
												<UOMCoded>EA</UOMCoded>
											</UnitOfMeasurement>
										</Quantity>
									</PriceBasisQuantity>
								</Price>
							</ListOfPrice>
							<Tax>
								<TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded>
								<TaxCategoryCoded>StandardRate</TaxCategoryCoded>
								<TaxTypeCoded>ValueAddedTax</TaxTypeCoded>
								<TaxPercent>.00</TaxPercent>
								<TaxableAmount>100.00</TaxableAmount>
								<TaxAmount>.00</TaxAmount>
							</Tax>
							<TotalValue>
								<MonetaryValue>
									<MonetaryAmount>200.00</MonetaryAmount>
								</MonetaryValue>
							</TotalValue>
						</PricingDetail>
						<DeliveryDetail>
							<ListOfScheduleLine>
								<ScheduleLine>
									<Quantity>
										<QuantityValue>2</QuantityValue>
										<UnitOfMeasurement>
											<UOMCoded>EA</UOMCoded>
										</UnitOfMeasurement>
									</Quantity>
									<RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate>
								</ScheduleLine>
							</ListOfScheduleLine>
						</DeliveryDetail>
					</ItemDetail>
				</ListOfItemDetail>
			</OrderDetail>
			<OrderSummary>
				<NumberOfLines>2</NumberOfLines>
				<TotalTax>
					<MonetaryValue>
						<MonetaryAmount>.00</MonetaryAmount>
					</MonetaryValue>
				</TotalTax>
				<TotalAmount>
					<MonetaryValue>
						<MonetaryAmount>220.00</MonetaryAmount>
						<Currency>
							<CurrencyCoded>NOK</CurrencyCoded>
						</Currency>
					</MonetaryValue>
				</TotalAmount>
			</OrderSummary>
		</Order>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Link to comment
Share on other sites

  • Solution

One way to do this, although I must admit I don't understand why people seem to insist on parsing SOAP responses rather than using SoapClient:

 

$xml = simplexml_load_file('soap.xml');
$xml->registerXPathNamespace('SOAP-ENV', "http://www.w3.org/2003/05/soap-envelope");
$body = $xml->xpath('SOAP-ENV:Body')[0];
echo $body->Order->OrderHeader->OrderNumber->BuyerOrderNumber;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.