Hi There, I am quite new to simpleXML and I would like to know how I can access child nodes by index singe I do not have the node name

The XML would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <SubRoot>
        <Content ItemType="ItemType1">
            <ItemDetails>
                <ItemDetail>
                    <City Code="CPT"><![CDATA[Cape Town]]>
                    </City>
                    <Item Code="000000000001"><![CDATA[Random Text here]]>
                    </Item>
                    <ItemInformation>
                        <Segment1>
                            <Segmentchild1 Code="H"><![CDATA[XXXXXX]]>
                            </Segmentchild1>
                            **<UNKNOWNNODE Code="CPT"><![CDATA[XXXXXXXX]]>
                            </UNKNOWNNODE>**
                        </Segment1>
                        <Segment2>
                            <Segmentchild1 Code="A"><![CDATA[XXXXXX]]>
                            </Segmentchild1>
                            **<UNKNOWNNODE Code="CPT"><![CDATA[XXXXXXXX]]>
                            </UNKNOWNNODE>**
                        </Segment2>
                    <ItemInformation>
                </ItemDetail>
            </ItemDetails>
        </Content>
    </SubRoot>
</Root>

How can i access the UNKNOWNNODE nodes value and attributes?

I access the nodes like this:
$transferDetails = $xmlResponse->SubRoot->Content->ItemDetails->children();

Does the unknown node always have the Code="CPT" attribute and is the only node within the <SegmentX> node to contain such an attribute value?

If so you could do something along the lines of search the <SegmentX> child nodes for a node with the matching attribute.

Unfortunately I am a .Net developer so can't deliver on the PHP code front but have toyed with XML enough to try give an insight into logic you could use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.