Solved

Reading a value from XML with namespaces

Posted on 2011-09-13
10
324 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
  • 5
  • 4
10 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
0
 
LVL 19

Author Comment

by:elimesika
Comment Utility
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
Comment Utility
also , I would like to get the value with XPATH and not by loping all nodes ....
0
 
LVL 47

Expert Comment

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

Author Comment

by:elimesika
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
    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
Comment Utility
> 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
Comment Utility
Thanks a lot !!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 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

9 Experts available now in Live!

Get 1:1 Help Now