Solved

xmldom getlength gives me only 1?

Posted on 2008-10-14
3
653 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 73

Expert Comment

by:sdstuber
Comment Utility
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
Comment Utility
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 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now