Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:19:45+00:00 2026-06-17T18:19:45+00:00

I have this xml and when I try to get the node: InternetGatewayDevice->WANDevice->i2 with

  • 0

I have this xml and when I try to get the node: InternetGatewayDevice->WANDevice->i2 with getElementsByTagName it fails. It works only with xpath. Here is the code:

The XML:

<?xml version="1.0" encoding="UTF-8"?>
<InternetGatewayDevice>
        <LANDevice>
                <i1>
                </i1>
        </LANDevice>
        <Time>
                <X_ZyXEL_DefaultRouteProfileName PARAMETER="configured" TYPE="string" LENGTH="256"></X_ZyXEL_DefaultRouteProfileName>
                <LocalTimeZoneName PARAMETER="configured" TYPE="string" LENGTH="64">CET-1CEST-2,M3.5.0/1,M10.5.0/1</LocalTimeZoneName>
                <NTPServer5 PARAMETER="configured" TYPE="string" LENGTH="64"></NTPServer5>
                <NTPServer4 PARAMETER="configured" TYPE="string" LENGTH="64"></NTPServer4>
                <NTPServer3 PARAMETER="configured" TYPE="string" LENGTH="64"></NTPServer3>
                <NTPServer2 PARAMETER="configured" TYPE="string" LENGTH="64"></NTPServer2>
                <NTPServer1 PARAMETER="configured" TYPE="string" LENGTH="64">europe.pool.ntp.org</NTPServer1>
                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
        </Time>
        <WANDevice>
                <i1>
                        <WANEthernetInterfaceConfig>
                                <DuplexMode PARAMETER="configured" TYPE="string" LENGTH="32">Auto</DuplexMode>
                                <MaxBitRate PARAMETER="configured" TYPE="string" LENGTH="32">Auto</MaxBitRate>
                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                        </WANEthernetInterfaceConfig>
                        <WANConnectionDevice>
                                <i1>
                                        <X_ZyXEL_WANService PARAMETER="configured" TYPE="string" LENGTH="63"></X_ZyXEL_WANService>
                                        <X_ZyXEL_EgressQueue PARAMETER="configured" TYPE="uint8" MAX="255" MIN="0">0</X_ZyXEL_EgressQueue>
                                        <X_ZyXEL_L2VlanMuxMode PARAMETER="configured" TYPE="boolean">1</X_ZyXEL_L2VlanMuxMode>
                                        <WANIPConnection>
                                                <i1>
                                                        <X_ZyXEL_IPv6DefaultGateway PARAMETER="configured" TYPE="string" LENGTH="46">fe80::1</X_ZyXEL_IPv6DefaultGateway>
                                                        <RouteProtocolRx PARAMETER="configured" TYPE="string" LENGTH="10">Off</RouteProtocolRx>
                                                        <ConnectionTrigger PARAMETER="configured" TYPE="string" LENGTH="10">AlwaysOn</ConnectionTrigger>
                                                        <X_ZyXEL_Multicast PARAMETER="configured" TYPE="string" LENGTH="8">IGMPv3</X_ZyXEL_Multicast>
                                                        <DNSServers PARAMETER="configured" TYPE="string" LENGTH="64"></DNSServers>
                                                        <DefaultGateway PARAMETER="configured" TYPE="string" LENGTH="16"></DefaultGateway>
                                                        <SubnetMask PARAMETER="configured" TYPE="string" LENGTH="16"></SubnetMask>
                                                        <ExternalIPAddress PARAMETER="configured" TYPE="string" LENGTH="16"></ExternalIPAddress>
                                                        <AddressingType PARAMETER="configured" TYPE="string" LENGTH="8">DHCP</AddressingType>
                                                        <Name PARAMETER="configured" TYPE="string" LENGTH="256">EtherWAN1</Name>
                                                        <ConnectionType PARAMETER="configured" TYPE="string" LENGTH="13">IP_Routed</ConnectionType>
                                                        <X_ZyXEL_DualStack PARAMETER="configured" TYPE="uint8" MAX="2" MIN="0">1</X_ZyXEL_DualStack>
                                                        <X_ZyXEL_PassThrough PARAMETER="configured" TYPE="boolean">0</X_ZyXEL_PassThrough>
                                                        <X_ZyXEL_Routing PARAMETER="configured" TYPE="uint8" MAX="2" MIN="0">1</X_ZyXEL_Routing>
                                                        <X_ZyXEL_VlanMux8021p PARAMETER="configured" TYPE="uint8" MAX="7" MIN="0">0</X_ZyXEL_VlanMux8021p>
                                                        <MACAddressOverride PARAMETER="configured" TYPE="boolean">0</MACAddressOverride>
                                                        <MACAddress PARAMETER="configured" TYPE="mac">00:00:00:00:00:00</MACAddress>
                                                        <X_ZyXEL_AutoBridge PARAMETER="configured" TYPE="boolean">0</X_ZyXEL_AutoBridge>
                                                        <DNSOverrideAllowed PARAMETER="configured" TYPE="boolean">0</DNSOverrideAllowed>
                                                        <DNSEnabled PARAMETER="configured" TYPE="boolean">1</DNSEnabled>
                                                        <NATEnabled PARAMETER="configured" TYPE="boolean">1</NATEnabled>
                                                        <X_ZyXEL_L2Bridging_AvailableInterfaceKey PARAMETER="configured" TYPE="uint8" MAX="255" MIN="0">17</X_ZyXEL_L2Bridging_AvailableInterfaceKey>
                                                        <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                        <X_ZyXEL_VLanMuxId PARAMETER="configured" TYPE="uint16" MAX="4094" MIN="0">3900</X_ZyXEL_VLanMuxId>
                                                        <MaxMTUSize PARAMETER="configured" TYPE="uint16" MAX="1540" MIN="1">1500</MaxMTUSize>
                                                        <ShapingRate PARAMETER="configured" TYPE="sint31" MAX="2147483647" MIN="-1">-1</ShapingRate>
                                                        <X_ZyXEL_IPv6DNS>
                                                                <i1>
                                                                        <ServerIP PARAMETER="configured" TYPE="string" LENGTH="46">::1</ServerIP>
                                                                        <ServerType PARAMETER="configured" TYPE="string" LENGTH="32">FromISP</ServerType>
                                                                </i1>
                                                        </X_ZyXEL_IPv6DNS>
                                                        <X_ZyXEL_NAT>
                                                                <DefaultServerIP PARAMETER="configured" TYPE="string" LENGTH="16"></DefaultServerIP>
                                                                <DefaultServerIPEnabled PARAMETER="configured" TYPE="boolean">0</DefaultServerIPEnabled>
                                                                <Loopback PARAMETER="configured" TYPE="boolean">0</Loopback>
                                                                <LookupRule>
                                                                        <i1>
                                                                                <GlobalEnd PARAMETER="configured" TYPE="string" LENGTH="16">0.0.0.0</GlobalEnd>
                                                                                <GlobalStart PARAMETER="configured" TYPE="string" LENGTH="16">0.0.0.0</GlobalStart>
                                                                                <LocalEnd PARAMETER="configured" TYPE="string" LENGTH="16">255.255.255.255</LocalEnd>
                                                                                <LocalStart PARAMETER="configured" TYPE="string" LENGTH="16">0.0.0.0</LocalStart>
                                                                                <DeviceWANIP PARAMETER="configured" TYPE="boolean">1</DeviceWANIP>
                                                                                <NATRuleEnabled PARAMETER="configured" TYPE="boolean">1</NATRuleEnabled>
                                                                                <Type PARAMETER="configured" TYPE="uint8" MAX="3" MIN="0">1</Type>
                                                                        </i1>
                                                                </LookupRule>
                                                        </X_ZyXEL_NAT>
                                                        <X_ZyXEL_IPv6GlobalAddress>
                                                                <i1>
                                                                        <Address PARAMETER="configured" TYPE="string" LENGTH="46">::</Address>
                                                                        <AddressingType PARAMETER="configured" TYPE="string" LENGTH="10">DHCPv6</AddressingType>
                                                                        <PrefixLength PARAMETER="configured" TYPE="uint8" MAX="64" MIN="16">64</PrefixLength>
                                                                </i1>
                                                        </X_ZyXEL_IPv6GlobalAddress>
                                                        <X_ZyXEL_DNS>
                                                                <i1>
                                                                        <ServerIP PARAMETER="configured" TYPE="string" LENGTH="16">0.0.0.0</ServerIP>
                                                                        <ServerType PARAMETER="configured" TYPE="string" LENGTH="32">FromISP</ServerType>
                                                                </i1>
                                                        </X_ZyXEL_DNS>
                                                        <X_ZyXEL_DHCPv6Client>
                                                                <SentDHCPOption>
                                                                        <i1>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">25</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i1>
                                                                        <i2>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">3</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i2>
                                                                        <i3>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">23</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i3>
                                                                </SentDHCPOption>
                                                        </X_ZyXEL_DHCPv6Client>
                                                        <DHCPClient>
                                                                <SentDHCPOption>
                                                                        <i1>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">60</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">0</Enable>
                                                                        </i1>
                                                                </SentDHCPOption>
                                                        </DHCPClient>
                                                </i1>
                                        </WANIPConnection>
                                </i1>
                        </WANConnectionDevice>
                </i1>
                <i2>
                        <WANDSLInterfaceConfig>
                                <LinkEncapsulationRequested PARAMETER="configured" TYPE="string" LENGTH="64">G.992.3_Annex_K_ATM</LinkEncapsulationRequested>
                                <Status PARAMETER="configured" TYPE="string" LENGTH="64">Up</Status>
                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                        </WANDSLInterfaceConfig>
                        <WANConnectionDevice>
                                <i1>
                                        <X_ZyXEL_WANService PARAMETER="configured" TYPE="string" LENGTH="63"></X_ZyXEL_WANService>
                                        <X_ZyXEL_EgressQueue PARAMETER="configured" TYPE="uint8" MAX="255" MIN="0">0</X_ZyXEL_EgressQueue>
                                        <X_ZyXEL_L2VlanMuxMode PARAMETER="configured" TYPE="boolean">0</X_ZyXEL_L2VlanMuxMode>
                                        <WANPPPConnection>
                                                <i1>
                                                        <X_ZyXEL_PPPAuthenticationProtocol PARAMETER="configured" TYPE="string" LENGTH="32">Auto</X_ZyXEL_PPPAuthenticationProtocol>
                                                        <RouteProtocolRx PARAMETER="configured" TYPE="string" LENGTH="10">Off</RouteProtocolRx>
                                                        <ConnectionTrigger PARAMETER="configured" TYPE="string" LENGTH="10">AlwaysOn</ConnectionTrigger>
                                                        <PPPoEServiceName PARAMETER="configured" TYPE="string" LENGTH="256"></PPPoEServiceName>
                                                        <PPPoEACName PARAMETER="configured" TYPE="string" LENGTH="256"></PPPoEACName>
                                                        <X_ZyXEL_Multicast PARAMETER="configured" TYPE="string" LENGTH="8">IGMPv3</X_ZyXEL_Multicast>
                                                        <DNSServers PARAMETER="configured" TYPE="string" LENGTH="64"></DNSServers>
                                                        <Password PARAMETER="configured" TYPE="string" LENGTH="64">a</Password>
                                                        <Username PARAMETER="configured" TYPE="string" LENGTH="64">ads</Username>
                                                        <Name PARAMETER="configured" TYPE="string" LENGTH="256">AdslWAN1</Name>
                                                        <ConnectionType PARAMETER="configured" TYPE="string" LENGTH="16">IP_Routed</ConnectionType>
                                                        <X_ZyXEL_StaticIP PARAMETER="configured" TYPE="string" LENGTH="16">1xx.20.7.5</X_ZyXEL_StaticIP>
                                                        <X_ZyXEL_DualStack PARAMETER="configured" TYPE="uint8" MAX="2" MIN="0">0</X_ZyXEL_DualStack>
                                                        <X_ZyXEL_Routing PARAMETER="configured" TYPE="uint8" MAX="2" MIN="0">1</X_ZyXEL_Routing>
                                                        <X_ZyXEL_VlanMux8021p PARAMETER="configured" TYPE="uint8" MAX="7" MIN="0">0</X_ZyXEL_VlanMux8021p>
                                                        <X_ZyXEL_PassThrough PARAMETER="configured" TYPE="boolean">1</X_ZyXEL_PassThrough>
                                                        <MACAddressOverride PARAMETER="configured" TYPE="boolean">0</MACAddressOverride>
                                                        <MACAddress PARAMETER="configured" TYPE="mac">xx</MACAddress>
                                                        <X_ZyXEL_AutoBridge PARAMETER="configured" TYPE="boolean">0</X_ZyXEL_AutoBridge>
                                                        <DNSOverrideAllowed PARAMETER="configured" TYPE="boolean">0</DNSOverrideAllowed>
                                                        <DNSEnabled PARAMETER="configured" TYPE="boolean">1</DNSEnabled>
                                                        <NATEnabled PARAMETER="configured" TYPE="boolean">0</NATEnabled>
                                                        <X_ZyXEL_L2Bridging_AvailableInterfaceKey PARAMETER="configured" TYPE="uint8" MAX="255" MIN="0">0</X_ZyXEL_L2Bridging_AvailableInterfaceKey>
                                                        <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                        <X_ZyXEL_VLanMuxId PARAMETER="configured" TYPE="uint16" MAX="4094" MIN="0">0</X_ZyXEL_VLanMuxId>
                                                        <ShapingRate PARAMETER="configured" TYPE="sint31" MAX="2147483647" MIN="-1">-1</ShapingRate>
                                                        <IdleDisconnectTime PARAMETER="configured" TYPE="uint32" MAX="4294967295" MIN="0">0</IdleDisconnectTime>
                                                        <AutoDisconnectTime PARAMETER="configured" TYPE="uint32" MAX="4294967295" MIN="0">0</AutoDisconnectTime>
                                                        <X_ZyXEL_DNS>
                                                                <i1>
                                                                        <ServerIP PARAMETER="configured" TYPE="string" LENGTH="16">xx</ServerIP>
                                                                        <ServerType PARAMETER="configured" TYPE="string" LENGTH="32">UserDefined</ServerType>
                                                                </i1>
                                                                <i2>
                                                                        <ServerIP PARAMETER="configured" TYPE="string" LENGTH="16">xx</ServerIP>
                                                                        <ServerType PARAMETER="configured" TYPE="string" LENGTH="32">UserDefined</ServerType>
                                                                </i2>
                                                        </X_ZyXEL_DNS>
                                                        <X_ZyXEL_IPv6GlobalAddress>
                                                                <i1>
                                                                        <Address PARAMETER="configured" TYPE="string" LENGTH="46">::</Address>
                                                                        <AddressingType PARAMETER="configured" TYPE="string" LENGTH="10">DHCPv6</AddressingType>
                                                                        <PrefixLength PARAMETER="configured" TYPE="uint8" MAX="64" MIN="16">64</PrefixLength>
                                                                </i1>
                                                        </X_ZyXEL_IPv6GlobalAddress>
                                                        <X_ZyXEL_IPv6DNS>
                                                                <i1>
                                                                        <ServerIP PARAMETER="configured" TYPE="string" LENGTH="46">::</ServerIP>
                                                                        <ServerType PARAMETER="configured" TYPE="string" LENGTH="32">FromISP</ServerType>
                                                                </i1>
                                                        </X_ZyXEL_IPv6DNS>
                                                        <X_ZyXEL_DHCPv6Client>
                                                                <SentDHCPOption>
                                                                        <i1>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">25</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i1>
                                                                        <i2>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">3</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i2>
                                                                        <i3>
                                                                                <Value PARAMETER="configured" TYPE="string" LENGTH="340"></Value>
                                                                                <Tag PARAMETER="configured" TYPE="uint8" MAX="254" MIN="1">23</Tag>
                                                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                                        </i3>
                                                                </SentDHCPOption>
                                                        </X_ZyXEL_DHCPv6Client>
                                                </i1>
                                        </WANPPPConnection>
                                        <WANDSLLinkConfig>
                                                <X_ZyXEL_IfName PARAMETER="configured" TYPE="string" LENGTH="16">nas1</X_ZyXEL_IfName>
                                                <ATMQoS PARAMETER="configured" TYPE="string" LENGTH="128">UBR</ATMQoS>
                                                <ATMEncapsulation PARAMETER="configured" TYPE="string" LENGTH="64">LLC</ATMEncapsulation>
                                                <DestinationAddress PARAMETER="configured" TYPE="string" LENGTH="256">PVC:8/35</DestinationAddress>
                                                <LinkType PARAMETER="configured" TYPE="string" LENGTH="32">EoA</LinkType>
                                                <X_ZyXEL_ATMEnbQos PARAMETER="configured" TYPE="boolean">0</X_ZyXEL_ATMEnbQos>
                                                <Enable PARAMETER="configured" TYPE="boolean">1</Enable>
                                                <X_ZyXEL_ATMSendBuffer PARAMETER="configured" TYPE="uint16" MAX="26144" MIN="0">0</X_ZyXEL_ATMSendBuffer>
                                                <ATMSustainableCellRate PARAMETER="configured" TYPE="uint32" MAX="4294967295" MIN="0">0</ATMSustainableCellRate>
                                                <ATMMaximumBurstSize PARAMETER="configured" TYPE="uint32" MAX="4294967295" MIN="0">0</ATMMaximumBurstSize>
                                                <ATMPeakCellRate PARAMETER="configured" TYPE="uint32" MAX="4294967295" MIN="0">0</ATMPeakCellRate>
                                        </WANDSLLinkConfig>
                                </i1>
                        </WANConnectionDevice>
                        <WANDSLDiagnostics>
                                <LoopDiagnosticsState PARAMETER="configured" EXTATTR="0x0002" TYPE="string" LENGTH="32">Complete</LoopDiagnosticsState>
                        </WANDSLDiagnostics>
                </i2>
        </WANDevice>
</InternetGatewayDevice>

The php:

$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load('file.xml');

//With getElementsByTagName
echo "getElementsByTagName:<br/>";
$node_of_xml = $xml->getElementsByTagName('InternetGatewayDevice')->item(0)->getElementsByTagName('WANDevice')->item(0)->getElementsByTagName('i2')->item(0);
foreach($node_of_xml->childNodes as $child) {
    echo $child->nodeName ."<br/>";
}
//With xpath
echo "<br/>Xpath:<br/>";
$xpath = new DOMXPath($xml);    
$results = $xpath->query('/InternetGatewayDevice/WANDevice/i2');   
$node_of_xml = $results->item(0);
foreach($node_of_xml->childNodes as $child) {
    echo $child->nodeName ."<br/>";
}

The output (getElementsByTagName is wrong, Xpath is correct):

getElementsByTagName:
Value
Tag
Enable

Xpath:
WANDSLInterfaceConfig
WANConnectionDevice
WANDSLDiagnostics

PHP Version 5.3.20
DOM/XML enabled
DOM/XML API Version 20031129
libxml Version 2.7.8

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:19:46+00:00Added an answer on June 17, 2026 at 6:19 pm

    getElementsByTagName is not limited to direct children. And the first i2 node within WANDevice is /InternetGatewayDevice/WANDevice/i1/WANConnectionDevice/i1/WANIPConnection/i1/X_ZyXEL_DHCPv6Client/SentDHCPOption/i2

    You provided the solution by yourself: XPath.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i get this error when i retrieve an XML that only has 1 node
i get this error when i retrieve an XML that only has 1 node
I have this code here that worked all this time in 2.3 now we
Here is my code: // get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {
I have the below XML. Here I want to get the previous sibling of
I have this xml file: <A> <B> <elt>Add</elt> ...there are some element here <bId>2</bId>
I have an xml file with a node that contains some c# code. <Script
I have this xml from which I am trying to grab the value in
I have this xml <products> <product> <name>Demo</name> </product> <product> <name>Black Beauty III</name> <description>Beautiful les
I have this xml file which has text init. i.e Hi my name is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.