Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

xmldom getlength gives me only 1?

Posted on 2008-10-14
3
656 Views
Last Modified: 2013-12-18
hi here is a snippet of my xml; when i do this in my pl.sql i get a count of 1? why is this so? i want to know the total no of nodes within <Parameters> so that i can run the loop.
 nl := xmldom.getElementsByTagName(doc, 'Parameters');
      len := xmldom.getLength(nl);
      htp.p('Length : ' || len);

<?xml version="1.0" encoding="utf-8"?>
<TestData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Status>CompletedNormally</TestCompletionStatus>
<ComputerName>DUILT10</ComputerName>
<StartTime>2008-03-19T15:12:23</StartTime>
---Some more noded----
<Parameters>
<RangeMeasured>
<Name>PDissBol-5[C]</Name>
<Min>1.22</Min>
<Max>1.36</Max>
<Units>W</Units>
</RangeMeasured>
<TextMeasured>
<Name>ComputerName</Name>
<Value>DUILT10</Value>
</TextMeasured>
<RangeMeasured>
<Name>TrackError25[C]To-5[C]</Name>
<Min>0.031</Min>
<Max>0.041</Max>
<Units>dB</Units>
</RangeMeasured>
<RangeMeasured>
<Name>Power-5[C]</Name>
<Min>1.988</Min>
<Max>1.061</Max>
<Units>dBm</Units>
</RangeMeasured>

---some more nodeds---
</Parameters>
</TestData>
0
Comment
Question by:samir25
  • 2
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 22721254
The problem is the sample data has only one "Parameters" node, so length=1  is correct. for the nodelist of "Parameters"

If you want the count of all nodes within Parameters you will need to get a DOMElement and call getchildrenbyname,  or otherwise iterate through the nodes inside that node and count them
0
 
LVL 1

Author Comment

by:samir25
ID: 22728090
what do you mean by i need to get a DOMElement? how can i do that?
basically i need to find a child inside Parameters node
e.g. <RangeMeasured>
<Name>TrackError25[C]To-5[C]</Name>
<Min>0.031</Min>
<Max>0.041</Max>
<Units>dB</Units>
</RangeMeasured>
i need to find TrackError25[C]To-5[C]... and if exists then i need to change the min and max.
would you be able to help on this?
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 22732816
rather than using DOM parsing, can you use simple xpath queries?


something like this?
SELECT   EXTRACTVALUE(VALUE(x), '/*[Name="TrackError25[C]To-5[C]"]/Min') MIN,
         EXTRACTVALUE(VALUE(x), '/*[Name="TrackError25[C]To-5[C]"]/Max') MAX
  FROM   (SELECT   XMLTYPE('<?xml version="1.0" encoding="utf-8"?>
<TestData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TestCompletionStatus>CompletedNormally</TestCompletionStatus>
<ComputerName>DUILT10</ComputerName>
<StartTime>2008-03-19T15:12:23</StartTime>
<Parameters>
<RangeMeasured>
<Name>Sean</Name>
<Min>1.22</Min>
<Max>1.36</Max>
<Units>W</Units>
</RangeMeasured>
<RangeMeasured>
<Name>PDissBol-5[C]</Name>
<Min>1.22</Min>
<Max>1.36</Max>
<Units>W</Units>
</RangeMeasured>
<TextMeasured>
<Name>ComputerName</Name>
<Value>DUILT10</Value>
</TextMeasured>
<RangeMeasured>
<Name>TrackError25[C]To-5[C]</Name>
<Min>0.031</Min>
<Max>0.041</Max>
<Units>dB</Units>
</RangeMeasured>
<RangeMeasured>
<Name>Power-5[C]</Name>
<Min>1.988</Min>
<Max>1.061</Max>
<Units>dBm</Units>
</RangeMeasured>
</Parameters>
</TestData>
')
                       xml
            FROM   DUAL),
         TABLE(XMLSEQUENCE(EXTRACT(
                               xml,
                               '/TestData/Parameters/RangeMeasured[Name="TrackError25[C]To-5[C]"]'
                           ))) x

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eliminate additional border 1 22
Input a SQl, output tables amd columns used in the SQL 19 55
plsql job on oracle 18 33
parsing xml using powershell 6 15
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question