Solved

Reading a value from XML with namespaces

Posted on 2011-09-13
10
364 Views
Last Modified: 2012-05-12
HI
I have a document with the following root :
<xxx:Envelope xxx:version="yyy">

How do I get the version attribute value from java code ?

Thanks
0
Comment
Question by:elimesika
[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
  • 5
  • 4
10 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36533572
0
 
LVL 19

Author Comment

by:elimesika
ID: 36533581
hi
Thanks for the quick respond , but I didn't found in your example how to get a value that is prefixed by a namespace (xxx:version)  
Please elaborate

Thanks
0
 
LVL 19

Author Comment

by:elimesika
ID: 36533587
also , I would like to get the value with XPATH and not by loping all nodes ....
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 47

Expert Comment

by:for_yan
ID: 36533626
Can you post an example of the actual file you want to read ?
0
 
LVL 19

Author Comment

by:elimesika
ID: 36533675
HI
Here it is
I want to get the ovf:version value

Thanks
<?xml version='1.0' encoding='UTF-8'?><ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1/" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ovf:version="1.0"><References><File ovf:href="f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff" ovf:id="5ee9b198-ba30-44d2-8304-5abe331dc3ff" ovf:size="0" ovf:description="_Master_01/06/2010 17:36:05_template" /></References><Section xsi:type="ovf:NetworkSection_Type"><Info>List of networks</Info><Network ovf:name="Network 1" /></Section><Section xsi:type="ovf:DiskSection_Type"><Info>List of Virtual Disks</Info><Disk ovf:diskId="5ee9b198-ba30-44d2-8304-5abe331dc3ff" ovf:size="0" ovf:actual_size="0" ovf:vm_snapshot_id="dcd8f3a3-4f3b-4727-b2e6-b8e9ec5804d1" ovf:parentRef="" ovf:fileRef="f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff" ovf:format="http://www.vmware.com/specifications/vmdk.html#sparse" ovf:volume-format="RAW" ovf:volume-type="Sparse" ovf:disk-interface="IDE" ovf:disk-type="System" ovf:boot="true" ovf:wipe-after-delete="false" /></Section><Content ovf:id="out" xsi:type="ovf:VirtualSystem_Type"><Name>Master</Name><TemplateId>a36a7ea2-d434-45cb-b32f-7a6c269c97ea</TemplateId><Description></Description><Domain></Domain><CreationDate>2010/06/01 02:36:00</CreationDate><IsAutoSuspend>false</IsAutoSuspend><TimeZone>Israel Standard Time</TimeZone><VmType>0</VmType><default_display_type>0</default_display_type><default_boot_sequence>0</default_boot_sequence><Section ovf:id="a36a7ea2-d434-45cb-b32f-7a6c269c97ea" ovf:required="false" xsi:type="ovf:OperatingSystemSection_Type"><Info>Guest Operating System</Info><Description>WindowsXP</Description></Section><Section xsi:type="ovf:VirtualHardwareSection_Type"><Info>1 CPU, 512 Memeory</Info><System><vssd:VirtualSystemType>XXXX 2.3.0.0</vssd:VirtualSystemType></System><Item><rasd:Caption>1 virtual cpu</rasd:Caption><rasd:Description>Number of virtual CPU</rasd:Description><rasd:InstanceId>1</rasd:InstanceId><rasd:ResourceType>3</rasd:ResourceType><rasd:num_of_sockets>1</rasd:num_of_sockets><rasd:cpu_per_socket>1</rasd:cpu_per_socket></Item><Item><rasd:Caption>512 MB of memory</rasd:Caption><rasd:Description>Memory Size</rasd:Description><rasd:InstanceId>2</rasd:InstanceId><rasd:ResourceType>4</rasd:ResourceType><rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits><rasd:VirtualQuantity>512</rasd:VirtualQuantity></Item><Item><rasd:Caption>Drive 1</rasd:Caption><rasd:InstanceId>5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:InstanceId><rasd:ResourceType>17</rasd:ResourceType><rasd:HostResource>f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:HostResource><rasd:Parent>00000000-0000-0000-0000-000000000000</rasd:Parent><rasd:Template>00000000-0000-0000-0000-000000000000</rasd:Template><rasd:ApplicationList></rasd:ApplicationList><rasd:StorageId>875bd4ea-88e2-440f-b5cb-2fc1efa3bb60</rasd:StorageId><rasd:StoragePoolId>106a6029-f6f0-4a5d-bb35-82d6b6448420</rasd:StoragePoolId><rasd:CreationDate>2010/06/01 11:25:50</rasd:CreationDate><rasd:LastModified>2010/06/01 11:25:50</rasd:LastModified></Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>3</rasd:InstanceId><rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>0</rasd:ResourceSubType><rasd:Connection>xxxx</rasd:Connection><rasd:Name>ddd</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>4</rasd:InstanceId><rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>2</rasd:ResourceSubType><rasd:Connection>xxxx</rasd:Connection><rasd:Name>eth0</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>USB Controller</rasd:Caption><rasd:InstanceId>5</rasd:InstanceId><rasd:ResourceType>23</rasd:ResourceType><rasd:UsbPolicy>Enabled</rasd:UsbPolicy></Item><Item><rasd:Caption>Graphical Controller</rasd:Caption><rasd:InstanceId>6</rasd:InstanceId><rasd:ResourceType>20</rasd:ResourceType><rasd:VirtualQuantity>1</rasd:VirtualQuantity></Item></Section></Content></ovf:Envelope>

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36533723
Don't know if this is what you want:

    String xmlData1 =    "<?xml version='1.0' encoding='UTF-8'?><ovf:Envelope xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1/\" xmlns:rasd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData\" " +
                "xmlns:vssd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "ovf:version=\"1.0\"><References><File ovf:href=\"f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:id=\"5ee9b198-ba30-44d2-8304-5abe331dc3ff\" " +
                "ovf:size=\"0\" ovf:description=\"_Master_01/06/2010 17:36:05_template\" /></References><Section xsi:type=\"ovf:NetworkSection_Type\">" +
                "<Info>List of networks</Info><Network ovf:name=\"Network 1\" /></Section><Section xsi:type=\"ovf:DiskSection_Type\"><Info>List of Virtual Disks</Info>" +
                "<Disk ovf:diskId=\"5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:size=\"0\" ovf:actual_size=\"0\" ovf:vm_snapshot_id=\"dcd8f3a3-4f3b-4727-b2e6-b8e9ec5804d1\" ovf:parentRef=\"\"" +
                " ovf:fileRef=\"f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:format=\"http://www.vmware.com/specifications/vmdk.html#sparse\"" +
                " ovf:volume-format=\"RAW\" ovf:volume-type=\"Sparse\" ovf:disk-interface=\"IDE\" ovf:disk-type=\"System\" ovf:boot=\"true\" " +
                "ovf:wipe-after-delete=\"false\" /></Section><Content ovf:id=\"out\" xsi:type=\"ovf:VirtualSystem_Type\"><Name>Master</Name>" +
                "<TemplateId>a36a7ea2-d434-45cb-b32f-7a6c269c97ea</TemplateId><Description></Description><Domain>" +
                "</Domain><CreationDate>2010/06/01 02:36:00</CreationDate><IsAutoSuspend>false</IsAutoSuspend>" +
                "<TimeZone>Israel Standard Time</TimeZone><VmType>0</VmType><default_display_type>0</default_display_type>" +
                "<default_boot_sequence>0</default_boot_sequence><Section ovf:id=\"a36a7ea2-d434-45cb-b32f-7a6c269c97ea\" ovf:required=\"false\" xsi:type=\"ovf:OperatingSystemSection_Type\">" +
                "<Info>Guest Operating System</Info><Description>WindowsXP</Description>" +
                "</Section><Section xsi:type=\"ovf:VirtualHardwareSection_Type\">" +
                "<Info>1 CPU, 512 Memeory</Info><System><vssd:VirtualSystemType>XXXX 2.3.0.0</vssd:VirtualSystemType>" +
                "</System><Item><rasd:Caption>1 virtual cpu</rasd:Caption><rasd:Description>Number of virtual CPU</rasd:Description>" +
                "<rasd:InstanceId>1</rasd:InstanceId><rasd:ResourceType>3</rasd:ResourceType><rasd:num_of_sockets>1</rasd:num_of_sockets>" +
                "<rasd:cpu_per_socket>1</rasd:cpu_per_socket></Item><Item><rasd:Caption>512 MB of memory</rasd:Caption>" +
                "<rasd:Description>Memory Size</rasd:Description>" +
                "<rasd:InstanceId>2</rasd:InstanceId><rasd:ResourceType>4</rasd:ResourceType><rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>" +
                "<rasd:VirtualQuantity>512</rasd:VirtualQuantity></Item><Item><rasd:Caption>Drive 1</rasd:Caption>" +
                "<rasd:InstanceId>5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:InstanceId><rasd:ResourceType>17</rasd:ResourceType>" +
                "<rasd:HostResource>f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:HostResource>" +
                "<rasd:Parent>00000000-0000-0000-0000-000000000000</rasd:Parent>" +
                "<rasd:Template>00000000-0000-0000-0000-000000000000</rasd:Template>" +
                "<rasd:ApplicationList></rasd:ApplicationList><rasd:StorageId>875bd4ea-88e2-440f-b5cb-2fc1efa3bb60</rasd:StorageId>" +
                "<rasd:StoragePoolId>106a6029-f6f0-4a5d-bb35-82d6b6448420</rasd:StoragePoolId>" +
                "<rasd:CreationDate>2010/06/01 11:25:50</rasd:CreationDate><rasd:LastModified>2010/06/01 11:25:50</rasd:LastModified>" +
                "</Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>3</rasd:InstanceId>" +
                "<rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>0</rasd:ResourceSubType><rasd:Connection>xxxx</rasd:Connection>" +
                "<rasd:Name>ddd</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>4</rasd:InstanceId><rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>2</rasd:ResourceSubType>" +
                "<rasd:Connection>xxxx</rasd:Connection><rasd:Name>eth0</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>USB Controller</rasd:Caption><rasd:InstanceId>5</rasd:InstanceId><rasd:ResourceType>23</rasd:ResourceType><rasd:UsbPolicy>Enabled</rasd:UsbPolicy>" +
                "</Item><Item><rasd:Caption>Graphical Controller</rasd:Caption><rasd:InstanceId>6</rasd:InstanceId><rasd:ResourceType>20</rasd:ResourceType>" +
                "<rasd:VirtualQuantity>1</rasd:VirtualQuantity></Item></Section></Content></ovf:Envelope>";




        InputSource source = new InputSource(new StringReader(xmlData1));

        XPath xPath = XPathFactory.newInstance().newXPath();

        NodeList list = null;
         NodeList list1 = null;
        try {
            xPath.setNamespaceContext(new NamespaceContext() {
                public String getNamespaceURI(String prefix) {
                    return "http://schemas.dmtf.org/ovf/envelope/1/";
                }
                public String getPrefix(String namespaceURI) {
                    return "ovf";
                }
                public Iterator getPrefixes(String namespaceURI) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            });

   

             list = (NodeList) xPath.evaluate("//ovf:Envelope",  source, XPathConstants.NODESET);


        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        for (int i = 0; i < list.getLength(); i++) {
            NamedNodeMap atr =  list.item(i).getAttributes();
            for(int j=0; j<atr.getLength(); j++){
                System.out.println(atr.item(j).getNodeName());
                  System.out.println(atr.item(j).getNodeValue());
                  System.out.println(atr.item(j).getNamespaceURI());
            }
            
           // System.out.println(atr);
            
            System.out.println(list.item(i).getTextContent());
        }


        

Open in new window


Output:

ovf:version
1.0
http://schemas.dmtf.org/ovf/envelope/1/
xmlns:ovf
http://schemas.dmtf.org/ovf/envelope/1/
http://www.w3.org/2000/xmlns/
xmlns:rasd
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData
http://www.w3.org/2000/xmlns/
xmlns:vssd
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData
http://www.w3.org/2000/xmlns/
xmlns:xsi
http://www.w3.org/2001/XMLSchema-instance
http://www.w3.org/2000/xmlns/
List of networksList of Virtual DisksMastera36a7ea2-d434-45cb-b32f-7a6c269c97ea2010/06/01 02:36:00falseIsrael Standard Time000Guest Operating SystemWindowsXP1 CPU, 512 MemeoryXXXX 2.3.0.01 virtual cpuNumber of virtual CPU1311512 MB of memoryMemory Size24MegaBytes512Drive 15ee9b198-ba30-44d2-8304-5abe331dc3ff17f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff00000000-0000-0000-0000-00000000000000000000-0000-0000-0000-000000000000875bd4ea-88e2-440f-b5cb-2fc1efa3bb60106a6029-f6f0-4a5d-bb35-82d6b64484202010/06/01 11:25:502010/06/01 11:25:50Ethernet adapter on xxxx3100xxxxddd1000Ethernet adapter on xxxx4102xxxxeth01000USB Controller523EnabledGraphical Controller6201

Open in new window


0
 
LVL 19

Author Comment

by:elimesika
ID: 36533731
HI

Thanks again

If I want the output  to be only "1.0" (the value of ovf:version in the document)
Is there a direct way to access this value in XPATH without looping all notes ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36533741
    String xmlData1 =    "<?xml version='1.0' encoding='UTF-8'?><ovf:Envelope xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1/\" xmlns:rasd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData\" " +
                "xmlns:vssd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "ovf:version=\"1.0\"><References><File ovf:href=\"f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:id=\"5ee9b198-ba30-44d2-8304-5abe331dc3ff\" " +
                "ovf:size=\"0\" ovf:description=\"_Master_01/06/2010 17:36:05_template\" /></References><Section xsi:type=\"ovf:NetworkSection_Type\">" +
                "<Info>List of networks</Info><Network ovf:name=\"Network 1\" /></Section><Section xsi:type=\"ovf:DiskSection_Type\"><Info>List of Virtual Disks</Info>" +
                "<Disk ovf:diskId=\"5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:size=\"0\" ovf:actual_size=\"0\" ovf:vm_snapshot_id=\"dcd8f3a3-4f3b-4727-b2e6-b8e9ec5804d1\" ovf:parentRef=\"\"" +
                " ovf:fileRef=\"f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff\" ovf:format=\"http://www.vmware.com/specifications/vmdk.html#sparse\"" +
                " ovf:volume-format=\"RAW\" ovf:volume-type=\"Sparse\" ovf:disk-interface=\"IDE\" ovf:disk-type=\"System\" ovf:boot=\"true\" " +
                "ovf:wipe-after-delete=\"false\" /></Section><Content ovf:id=\"out\" xsi:type=\"ovf:VirtualSystem_Type\"><Name>Master</Name>" +
                "<TemplateId>a36a7ea2-d434-45cb-b32f-7a6c269c97ea</TemplateId><Description></Description><Domain>" +
                "</Domain><CreationDate>2010/06/01 02:36:00</CreationDate><IsAutoSuspend>false</IsAutoSuspend>" +
                "<TimeZone>Israel Standard Time</TimeZone><VmType>0</VmType><default_display_type>0</default_display_type>" +
                "<default_boot_sequence>0</default_boot_sequence><Section ovf:id=\"a36a7ea2-d434-45cb-b32f-7a6c269c97ea\" ovf:required=\"false\" xsi:type=\"ovf:OperatingSystemSection_Type\">" +
                "<Info>Guest Operating System</Info><Description>WindowsXP</Description>" +
                "</Section><Section xsi:type=\"ovf:VirtualHardwareSection_Type\">" +
                "<Info>1 CPU, 512 Memeory</Info><System><vssd:VirtualSystemType>XXXX 2.3.0.0</vssd:VirtualSystemType>" +
                "</System><Item><rasd:Caption>1 virtual cpu</rasd:Caption><rasd:Description>Number of virtual CPU</rasd:Description>" +
                "<rasd:InstanceId>1</rasd:InstanceId><rasd:ResourceType>3</rasd:ResourceType><rasd:num_of_sockets>1</rasd:num_of_sockets>" +
                "<rasd:cpu_per_socket>1</rasd:cpu_per_socket></Item><Item><rasd:Caption>512 MB of memory</rasd:Caption>" +
                "<rasd:Description>Memory Size</rasd:Description>" +
                "<rasd:InstanceId>2</rasd:InstanceId><rasd:ResourceType>4</rasd:ResourceType><rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>" +
                "<rasd:VirtualQuantity>512</rasd:VirtualQuantity></Item><Item><rasd:Caption>Drive 1</rasd:Caption>" +
                "<rasd:InstanceId>5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:InstanceId><rasd:ResourceType>17</rasd:ResourceType>" +
                "<rasd:HostResource>f4448fd6-59ec-4af2-bc13-92cc87bcdb78/5ee9b198-ba30-44d2-8304-5abe331dc3ff</rasd:HostResource>" +
                "<rasd:Parent>00000000-0000-0000-0000-000000000000</rasd:Parent>" +
                "<rasd:Template>00000000-0000-0000-0000-000000000000</rasd:Template>" +
                "<rasd:ApplicationList></rasd:ApplicationList><rasd:StorageId>875bd4ea-88e2-440f-b5cb-2fc1efa3bb60</rasd:StorageId>" +
                "<rasd:StoragePoolId>106a6029-f6f0-4a5d-bb35-82d6b6448420</rasd:StoragePoolId>" +
                "<rasd:CreationDate>2010/06/01 11:25:50</rasd:CreationDate><rasd:LastModified>2010/06/01 11:25:50</rasd:LastModified>" +
                "</Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>3</rasd:InstanceId>" +
                "<rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>0</rasd:ResourceSubType><rasd:Connection>xxxx</rasd:Connection>" +
                "<rasd:Name>ddd</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>Ethernet adapter on xxxx</rasd:Caption><rasd:InstanceId>4</rasd:InstanceId><rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>2</rasd:ResourceSubType>" +
                "<rasd:Connection>xxxx</rasd:Connection><rasd:Name>eth0</rasd:Name><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>USB Controller</rasd:Caption><rasd:InstanceId>5</rasd:InstanceId><rasd:ResourceType>23</rasd:ResourceType><rasd:UsbPolicy>Enabled</rasd:UsbPolicy>" +
                "</Item><Item><rasd:Caption>Graphical Controller</rasd:Caption><rasd:InstanceId>6</rasd:InstanceId><rasd:ResourceType>20</rasd:ResourceType>" +
                "<rasd:VirtualQuantity>1</rasd:VirtualQuantity></Item></Section></Content></ovf:Envelope>";




        InputSource source = new InputSource(new StringReader(xmlData1));

        XPath xPath = XPathFactory.newInstance().newXPath();

        NodeList list = null;
         NodeList list1 = null;
        try {
            xPath.setNamespaceContext(new NamespaceContext() {
                public String getNamespaceURI(String prefix) {
                    return "http://schemas.dmtf.org/ovf/envelope/1/";
                }
                public String getPrefix(String namespaceURI) {
                    return "ovf";
                }
                public Iterator getPrefixes(String namespaceURI) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            });

       

             list = (NodeList) xPath.evaluate("//ovf:Envelope",  source, XPathConstants.NODESET);


        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        for (int i = 0; i < list.getLength(); i++) {
            NamedNodeMap atr =  list.item(i).getAttributes();
            for(int j=0; j<atr.getLength(); j++){
                if(atr.item(j).getNodeName().indexOf("version") > -1)
                {
                     System.out.println(atr.item(j).getNodeName());
                        System.out.println(atr.item(j).getNodeValue());
                }

       
            }
            
    
        }

Open in new window


Output:

ovf:version
1.0

Open in new window

0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 36533853
> If I want the output  to be only "1.0" (the value of ovf:version in the document) Is there a direct way to access this value in XPATH without looping all notes ?

Yes. As above but change line 61 to the following...

String version = xPath.evaluate("/ovf:Envelope/@ovf:version",  source);


... and get rid of everything in the for loop (lines 68 to 81)
0
 
LVL 19

Author Closing Comment

by:elimesika
ID: 36533868
Thanks a lot !!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 88
JAVA API design with micro service cloud in mind 1 110
dao vs facade design patterns 2 69
convert Absolute path to relative path of FTP location 7 50
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

732 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