Solved

xmldom getlength gives me only 1?

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

932 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