0

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();

2
Contributors
1
Reply
21
Views
4 Years
Discussion Span
Last Post by Mike Askew
0

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.

Edited by Mike Askew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.