?
Solved

xmldom getlength gives me only 1?

Posted on 2008-10-14
3
Medium Priority
?
662 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
[X]
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
  • 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

762 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