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 6975331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:21:15+00:00 2026-05-27T17:21:15+00:00

Code: package com.parse; import org.w3c.dom.*; import javax.xml.xpath.*; import javax.xml.parsers.*; import java.io.IOException; import org.xml.sax.SAXException; public

  • 0

Code:

package com.parse;

import org.w3c.dom.*;

import javax.xml.xpath.*;
import javax.xml.parsers.*;
import java.io.IOException;
import org.xml.sax.SAXException;

public class XpathDemoOld {

  public static void main(String[] args) 
 throws ParserConfigurationException, SAXException, 
  IOException, XPathExpressionException {

  DocumentBuilderFactory domFactory = 
  DocumentBuilderFactory.newInstance();
  domFactory.setNamespaceAware(true); 
  DocumentBuilder builder = domFactory.newDocumentBuilder();
  Document doc = builder.parse("xml.xml");
  XPath xpath = XPathFactory.newInstance().newXPath();
   // XPath Query for showing all nodes value
  XPathExpression expr = xpath.compile("/QDTM_IN300301QD/controlActEvent/subject/subject/testCodeIdentifier/coveredPartyOf/financialTransactionEvent/subjectOf/annotation/code[@code='CPTCODE']/following-sibling::text/text()");

  Object result = expr.evaluate(doc, XPathConstants.NODESET);
  NodeList nodes = (NodeList) result;
  System.out.println("Length --- " + nodes.getLength());
  for (int i = 0; i < nodes.getLength(); i++) {

      System.out.println("Node Value--->" + nodes.item(i).getNodeValue()); 

  }
}
}

XML:

<?xml version="1.0" encoding="UTF-8"?>
<QDTM_IN300301QD ITSVersion="XML_1.0" xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 QDTM_IN300301QD.xsd ">
  <id assigningAuthorityName="TEST" extension="6399Z"/>
  <creationTime value="20111111121213" />
  <responseModeCode code="I"/>
  <versionCode code="V3-2010-12-Q2"/>
  <interactionId extension="QDTM_IN300301QD"/>
  <profileId extension="TBD"/>
  <processingCode code="P"/>
  <processingModeCode code="T"/>
  <acceptAckCode code="NE"/>
  <receiver  typeCode="RCV">
    <realmCode code="QD" />
    <device classCode="DEV" determinerCode="INSTANCE" >
      <realmCode code="QD" />
      <id assigningAuthorityName="RECEIVERID" extension="TESTCENTER"  /> <!-- These are identifiers for the recieving application and would be picked from the request message -->
    </device>
  </receiver>
  <sender  typeCode="SND">
    <realmCode code="QD" />  
    <device classCode="DEV" determinerCode="INSTANCE" >
      <realmCode code="QD" />
      <id assigningAuthorityName="SENDERID" extension="QTIM"  /> <!-- These are identifiers for the sending application and can be picked from the recieving section of the request message -->
    </device>
  </sender>
  <controlActEvent classCode="CACT" moodCode="EVN">
    <id assigningAuthorityName="TESTMESSAGEID" extension="6399Z" />
    <code code="TBD">
    </code>
    <statusCode code="Active"/>
    <subject contextConductionInd="true"> 
      <registrationEvent classCode="REG" moodCode="EVN">
        <realmCode code="QD" />
        <statusCode code="Active"/>
        <subject contextControlCode="AN" typeCode="SBJ">
      <realmCode code="QD" />
      <testCodeIdentifier classCode="ROL">
        <id assigningAuthorityName="PRMKEY" extension="SJC6399Z"/> <!-- This is a unique key in case of JDOS information. Might not be needed in case of FD. If it is decided that this is not required for FD then this can be removed -->
        <playingTestCodeDetails classCode="ENT" determinerCode="INSTANCE">
          <realmCode code="QD" />
          <id assigningAuthorityName="PRMORDCODE" extension="6399Z"  /><!--This is the primary order code for the test. Would be NTC in case of a Master-->
          <code code="6399Z" codeSystemName="QTIM"  >
           <originalText><![CDATA[Complete Blood Count]]></originalText>
           <originalText><![CDATA[Blood Cells]]></originalText>
          </code>
          <statusCode code="Active"/>
          <testCodeHasMember classCode="MBR" negationInd="true" >
          <subjectOf typeCode="SBJ">
            <annotation classCode="ACT" moodCode="EVN" >
             <realmCode code="QD" />
             <code code="INCLUDESHTMLENABLED"></code>
             <text><![CDATA[WBC, RBC, Hemoglobin, Hematocrit, MCV, MCH, MCHC, RDW, Platelet Count, MPV and Differential (Absolute and Percent - Neutrophils, Lymphocytes, Monocytes, Eosinophils, and Basophils) <br />
                 If abnormal cells are noted on a manual review of the peripheral blood smear or if the automated differential information meets specific criteria, a full manual differential will be performed.]]></text> <!-- Includes information is being passed here -->
             <statusCode code="Updated"/><!-- This flag would indicate if this field has been updated or not -->
           </annotation>
         </subjectOf>               
          </testCodeHasMember>
        </playingTestCodeDetails>
        <subjectOf typeCode="SBJ">
          <realmCode code="QD" />
          <order classCode="OBS" moodCode="EVN">
        <realmCode code="QD" />  
        <performer typeCode="PRF">
          <locatedEntity classCode="LOCE">
            <locatedOrganization classCode="ORG" determinerCode="INSTANCE">
            </locatedOrganization>
            <subjectOf typeCode="SBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <text><![CDATA[Quest Diagnostics Nichols Institute <br /> 33608 Ortega Highway <br /> San Juan Capistrano, CA 92690-6130]]></text> <!-- Performing lab address information would be passed here -->
            <statusCode code="Update"/><!-- This is the update flag for the performing lab address field-->
              </annotation>
            </subjectOf>
          </locatedEntity>
        </performer>
                <pertinentInformation2 typeCode="PERT">
          <observationEvent classCode="OBS" moodCode="EVN">
            <referenceRange nullFlavor="" typeCode="REFV">
              <interpretationRange classCode="OBS" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
                <code code="REFERENCERANGE"> <!-- Reference Range Information -->     
                </code>
                <text><![CDATA[IgA SUBCLASSES __IgA1 (UOM mg/dL) 6-11 months: 1-115 mg/dL 1 year: 3-120 mg/dL 2 years: 7-132 mg/dL 3 years: 11-143 mg/dL 4-7 years: 23-175 mg/dL 8-11 years: 33-204 mg/dL 12-17 years: 47-249 mg/dL >=18 years: 46-378 mg/dL IgA SUBCLASSES __IgA2 (UOM mg/dL) 6-11 months: 0-19 mg/dL 1 year: 0-23 mg/dL 2 years: 1-23 mg/dL 3 years: 1-25 mg/dL 4-7 years: 2-33 mg/dL 8-11 years: 2-37 mg/dL 12-17 years: 4-50 mg/dL >=18 years: 13-91 mg/dL IgA SUBCLASSES __IgA, Serum (UOM mg/dL) 6-11 months: 3-101 mg/dL 1 year: 6-112 mg/dL 2 years: 11-134 mg/dL 3 years: 16-155 mg/dL 4-7 years: 31-214 mg/dL 8-11 years: 43-268 mg/dL 12-17 years: 65-356 mg/dL >=18 years: 81-463 mg/dL]]></text>
                <statusCode code="token"/>
              </annotation>
            </subjectOf>
              </interpretationRange>
            </referenceRange>
           </observationEvent>
                </pertinentInformation2>
                <pertinentInformation3 typeCode="PERT">
          <scheduleEvent classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="SETUPSCHEDULE"/>
            <text><![CDATA[Set up: 6 days a week a.m.; Report available: 2-3 days]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </scheduleEvent>
        </pertinentInformation3>                
                <pertinentInformation3 typeCode="PERT">
          <scheduleEvent classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="SETUPTIME"/>
            <text><![CDATA[Set up: 6 days a week a.m.; Report available: 2-3 days]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </scheduleEvent>
        </pertinentInformation3> 
                <pertinentInformation3 typeCode="PERT">
          <scheduleEvent classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="SETUPDAYS"/>
            <text><![CDATA[Sets up 6 days a week.]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </scheduleEvent>
        </pertinentInformation3> 
               <pertinentInformation3 typeCode="PERT">
          <scheduleEvent classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="REPORTAVAILABLE"/>
            <text><![CDATA[2-3 days]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </scheduleEvent>
        </pertinentInformation3>        
                <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="PREFERREDSPECIMEN"/>
            <text><![CDATA[2 mL Second void urine <strong>or </strong>2-hour urine <strong>or </strong>&nbsp;2 mL Urine with no preservative]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="MINIMUMVOLUME"></code>
            <text><![CDATA[1 mL]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="OTHERACCEPTABLESPECIMEN"></code>
            <text><![CDATA[2 mL Second void urine <strong>or </strong>2-hour urine <strong>or </strong>&nbsp;2 mL Urine with no preservative]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="INSTRUCTIONS"></code>
            <text><![CDATA[<strong>Whole Blood: </strong>Normal phlebotomy procedure. Store and ship <br /> room temperature immediately. Do not freeze. <br /> <strong><br /> Saliva:</strong> Collect saliva using Oragnene self collection kit. Store and ship room temperatur immediately. Do not freeze.]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="TRANSPORTCONTAINER"></code>
            <text><![CDATA[APTIMA<sup>&reg;</sup> transport tube]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="TRANSPORTTEMPERATURE"></code>
            <text><![CDATA[<p>Refrigerated (cold packs)</p>]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="SPECIMENSTABILITY"></code>
            <text><![CDATA[Room temperature: 48 hours<br /> Refrigerated: 7 days<br /> Frozen: 30 days]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="REJECTCRITERIA"></code>
            <text><![CDATA[Specimens containing heparin; Leaking samples; Uncapped samples; Broken container; Non Aptima; Vaginal Swab Collection Kit]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>
        <pertinentInformation6 typeCode="PERT">
          <specimenHandling classCode="ACT" moodCode="EVN" >
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="PATIENTPREPARATION"></code>
            <text><![CDATA[<br/><b> Patient preparation:</b></br> Collect peak at end of 60 minutes IV infusion, 30 minutes after end of IV infusion, or 30-60 minutes after IM dose]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </specimenHandling>
        </pertinentInformation6>        
        <pertinentInformation7 typeCode="PERT">
          <medicalInformation classCode="ACT" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="METHODOLOGY"/>
            <text><![CDATA[Real-Time Polymerase Chain Reaction (RT-PCR)]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </medicalInformation>
        </pertinentInformation7>
        <pertinentInformation7 typeCode="PERT">
          <medicalInformation classCode="ACT" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="CLINICALSIGNIFICANCE"/>
            <text><![CDATA[Maternal Cell Contamination Study, STR Analysis, provides assurance that test results from fetal specimens are not influenced by contaminating maternal material. This test also allows for establishing the proper maternal-fetal relationship between specimens by using sophisticated analysis of 15 highly polymorphic STR loci.]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </medicalInformation>
        </pertinentInformation7>
        <pertinentInformation7 typeCode="PERT">
          <medicalInformation classCode="ACT" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="LIMITATION"/>
            <text><![CDATA[Variations in two genes (VKORC1 and CYP2C9) are particularly important in warfarin metabolism. VKORC1 may explain 30% of the variability in drug response between patients and changes in CYP2C9 may explain 10% of the dose variation. While significant portion of the dose variability can be accounted for by genetic factors, this testing will not determine all factors associated with dose variability.]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </medicalInformation>
        </pertinentInformation7>
        <pertinentInformation7 typeCode="PERT">
          <medicalInformation classCode="ACT" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="ASSAYVIEW"/>
            <text><![CDATA[Sample Value]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </medicalInformation>
        </pertinentInformation7>
        <pertinentInformation7 typeCode="PERT">
          <medicalInformation classCode="ACT" moodCode="EVN">
            <subjectOf typeCode="SUBJ">
              <annotation classCode="ACT" moodCode="EVN">
            <code code="INDICATIONS"/>
            <text><![CDATA[Sample Value]]></text>
            <statusCode code="Updated"/>
              </annotation>
            </subjectOf>
          </medicalInformation>
        </pertinentInformation7>        
          </order>
        </subjectOf>
        <coveredPartyOf typeCode="COV">
          <financialTransactionEvent classCode="XACT" moodCode="EVN">
        <id extension="12343" assigningAuthorityName="BILLCODE"/>
        <subjectOf  typeCode="SUBJ">
           <annotation classCode="ACT" moodCode="EVN" >
              <realmCode code="QD" />
              <code code="CPTCODE"></code>
              <text><![CDATA[Sample Value]]></text><!-- CPT Code information would be passed here -->
              <statusCode code="Updated"/><!-- Updated Flag for this field-->
          </annotation>
        </subjectOf>
          </financialTransactionEvent>
         </coveredPartyOf>
      </testCodeIdentifier>
        </subject>
        <custodian contextControlCode="AP" typeCode="CST">
          <assignedDevice classCode="ASSIGNED">
            <realmCode code="QD" />
            <id extension="QTIM"/>
            <assignedRepository classCode="DEV" determinerCode="INSTANCE">
              <name/>
            </assignedRepository>
          </assignedDevice>
        </custodian>
       </registrationEvent>
    </subject>
  </controlActEvent>
</QDTM_IN300301QD>

I have the above XML to be parsed using XPath; i am using the code on the top to parse using. I guess i am doing something wrong as it is not fetching the data for text tag when accessed by code tag code attribute = “CPTCODE”

Thanks in advance…

  • 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-05-27T17:21:16+00:00Added an answer on May 27, 2026 at 5:21 pm

    This is the most FAQ in XPath (search for XPath and default namespace).

    In short, Xpath always treats unprefixed names as belonging to “no namespace”.

    If an XML document has no default namespace, any element with unprefixed name does really belong to “no namespace” and the expression:

    /name1/name2
    

    selects any element named name2 that is a child of the top element named name1.

    In the case when the XML document has a globally defined default namespace the same expression:

    /name1/name2
    

    selects nothing, because there are no elements in “no namespace” (all elements are in the default, non-empty namespace), so trying to select such elements with names name1, name2 or whatevername results in 0 elements selected.

    The solution:

    Use your XPath engin API to “register a namespace” and an associated to it prefix, say "x". Then rewrite the expression as:

    /x:name1/x:name2
    

    This last expression correctly selects the wanted nodes.

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

Sidebar

Related Questions

I have the following simple Java code: package testj; import java.util.*; public class Query<T>
aka, what is wrong with this code:- package com.mez.appofjaq; import com.mez.appofjaq.RssParser.RssFeed; import android.app.Activity; import
i have this code package com.tct.soundTouch; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent;
The app code is package com.musicdownloader; import com.fortumo.android.PaymentActivity; import com.musicdownloader.R; import android.content.Intent; import android.net.Uri;
Please take a look at my code: package com.yarin.android.Examples_04_23; import android.app.Activity; import android.app.Notification; import
I'm running the following code.... package com.dc; import android.app.Activity; import android.content.Intent; import android.net.Uri; import
This piece of code is from Adobe docs : package { import flash.display.Loader; import
I want to package a piece of code that absolutely must run on Java
I have been running this code (from: http://blog.somethingaboutcode.com/?p=155 ): from twisted.internet import reactor from
When i try to read the xml from java using SAX parser, it 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.