Get Text from XML Element

Greetings All,

I have an XML string that has an element called <coordinates>.

I want to get the value of <coordinates>, but I can't seem to figure out how 
to reference it directly.

Below is the code for my function and the XML string...

If someone can point me in the right direction, I would appreciate it.

Thanks!!

Paul

Argument is string as 'strXML'
Return value is real as 'latitude'

messagebox("The passed string is",strXML)

real latitude

PBDOM_Builder pbdom_bldr
pbdom_document pbdom_doc
PBDOM_OBJECT pbdom_obj_array[]
PBDOM_Element pbdom_elem_root

pbdom_bldr = Create PBDOM_Builder
pbdom_doc = pbdom_bldr.BuildFromString(strXML)
pbdom_elem_root = pbdom_doc.GetRootElement()
boolean result
result = pbdom_doc.getcontent(pbdom_obj_array)

if result <> true then
 messagebox("Failed to getcontent",string(result))
else
 messagebox("Succeeded in getting getcontent",string(result))
end if


string coordinates_data
//coordinates_data = pbdom_doc.12.gettext()
coordinates_data = pbdom_elem_root.GetTextNormalize()

messagebox("coordinates_data",coordinates_data)

messagebox("LowerBound",string(lowerbound(pbdom_obj_array)))
messagebox("UpperBound",string(upperbound(pbdom_obj_array)))

integer i
for i = 1 to UpperBound(pbdom_obj_array)
 messagebox("Element is",string(pbdom_obj_array[i]))
next

return latitude

XML String is:

<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
  <name>2 Stanley Pl., Far Hills, NJ 07931</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">
    <address>2 Stanley Pl, Far Hills, NJ 07934, USA</address>
    <AddressDetails Accuracy="8" 
xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NJ</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Morris</SubAdministrativeAreaName><Locality><LocalityName>Far 
Hills</LocalityName><Thoroughfare><ThoroughfareName>2 Stanley 
Pl</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>07934</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="40.7429886" south="40.7366934" east="-74.6749984" 
west="-74.6812936" />
    </ExtendedData>
    <Point><coordinates>-74.6781460,40.7398410,0</coordinates></Point>
  </Placemark>
</Response></kml>


0
Paul
2/28/2010 8:57:50 PM
sybase.powerbuilder.xml 546 articles. 0 followers. Follow

3 Replies
739 Views

Similar Articles

[PageSpeed] 24

Paul

You could use GetChildElement/GetChildElements to find the coordinates
element. Before this function existed in PB I wrote a recursive
function to find an element. I used GetContent to retrieve the array of
elements of the first level, checked for type element, if found checked
for the name of the element I'm searching. If not found, I pass the
element to the function again.

Regards
Arthur
-- 



Paul Murray wrote:

> Greetings All,
> 
> I have an XML string that has an element called <coordinates>.
> 
> I want to get the value of <coordinates>, but I can't seem to figure
> out how to reference it directly.
> 
> Below is the code for my function and the XML string...
> 
> If someone can point me in the right direction, I would appreciate it.
> 
> Thanks!!
> 
> Paul
> 
> Argument is string as 'strXML'
> Return value is real as 'latitude'
> 
> messagebox("The passed string is",strXML)
> 
> real latitude
> 
> PBDOM_Builder pbdom_bldr
> pbdom_document pbdom_doc
> PBDOM_OBJECT pbdom_obj_array[]
> PBDOM_Element pbdom_elem_root
> 
> pbdom_bldr = Create PBDOM_Builder
> pbdom_doc = pbdom_bldr.BuildFromString(strXML)
> pbdom_elem_root = pbdom_doc.GetRootElement()
> boolean result
> result = pbdom_doc.getcontent(pbdom_obj_array)
> 
> if result <> true then
> messagebox("Failed to getcontent",string(result))
> else
> messagebox("Succeeded in getting getcontent",string(result))
> end if
> 
> 
> string coordinates_data
> //coordinates_data = pbdom_doc.12.gettext()
> coordinates_data = pbdom_elem_root.GetTextNormalize()
> 
> messagebox("coordinates_data",coordinates_data)
> 
> messagebox("LowerBound",string(lowerbound(pbdom_obj_array)))
> messagebox("UpperBound",string(upperbound(pbdom_obj_array)))
> 
> integer i
> for i = 1 to UpperBound(pbdom_obj_array)
> messagebox("Element is",string(pbdom_obj_array[i]))
> next
> 
> return latitude
> 
> XML String is:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <kml xmlns="http://earth.google.com/kml/2.0"><Response>
>  <name>2 Stanley Pl., Far Hills, NJ 07931</name>
>  <Status>
>    <code>200</code>
>    <request>geocode</request>
>  </Status>
>  <Placemark id="p1">
>    <address>2 Stanley Pl, Far Hills, NJ 07934, USA</address>
> <AddressDetails Accuracy="8"
> xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryName
> Code>US</CountryNameCode><CountryName>USA</CountryName><Administrative
> Area><AdministrativeAreaName>NJ</AdministrativeAreaName><SubAdministra
> tiveArea><SubAdministrativeAreaName>Morris</SubAdministrativeAreaName>
> <Locality><LocalityName>Far
> Hills</LocalityName><Thoroughfare><ThoroughfareName>2 Stanley
> Pl</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>0793
> 4</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></
> AdministrativeArea></Country></AddressDetails>    <ExtendedData>
> <LatLonBox north="40.7429886" south="40.7366934" east="-74.6749984"
> west="-74.6812936" />    </ExtendedData>
> <Point><coordinates>-74.6781460,40.7398410,0</coordinates></Point>
> </Placemark> </Response></kml>
0
Arthur
3/1/2010 5:03:09 AM
Thanks, Art!!

There are soooo many uses and means of implementing XML in this forum that I 
find it difficult to find what I am looking for...

I will try GetChildElement (I am only looking for one and it does not 
repeat).

I guess I thought that XML had been around long enough that you could simply 
feed in the XML and execute a function like:

variable = gettext(<coordinates>).

Thanks again for your help!

Paul


"Arthur Hefti" <arthur@catsoft.ch> wrote in message 
news:4b8b4a8d@forums-1-dub...
> Paul
>
> You could use GetChildElement/GetChildElements to find the coordinates
> element. Before this function existed in PB I wrote a recursive
> function to find an element. I used GetContent to retrieve the array of
> elements of the first level, checked for type element, if found checked
> for the name of the element I'm searching. If not found, I pass the
> element to the function again.
>
> Regards
> Arthur
> -- 
>
>
>
> Paul Murray wrote:
>
>> Greetings All,
>>
>> I have an XML string that has an element called <coordinates>.
>>
>> I want to get the value of <coordinates>, but I can't seem to figure
>> out how to reference it directly.
>>
>> Below is the code for my function and the XML string...
>>
>> If someone can point me in the right direction, I would appreciate it.
>>
>> Thanks!!
>>
>> Paul
>>
>> Argument is string as 'strXML'
>> Return value is real as 'latitude'
>>
>> messagebox("The passed string is",strXML)
>>
>> real latitude
>>
>> PBDOM_Builder pbdom_bldr
>> pbdom_document pbdom_doc
>> PBDOM_OBJECT pbdom_obj_array[]
>> PBDOM_Element pbdom_elem_root
>>
>> pbdom_bldr = Create PBDOM_Builder
>> pbdom_doc = pbdom_bldr.BuildFromString(strXML)
>> pbdom_elem_root = pbdom_doc.GetRootElement()
>> boolean result
>> result = pbdom_doc.getcontent(pbdom_obj_array)
>>
>> if result <> true then
>> messagebox("Failed to getcontent",string(result))
>> else
>> messagebox("Succeeded in getting getcontent",string(result))
>> end if
>>
>>
>> string coordinates_data
>> //coordinates_data = pbdom_doc.12.gettext()
>> coordinates_data = pbdom_elem_root.GetTextNormalize()
>>
>> messagebox("coordinates_data",coordinates_data)
>>
>> messagebox("LowerBound",string(lowerbound(pbdom_obj_array)))
>> messagebox("UpperBound",string(upperbound(pbdom_obj_array)))
>>
>> integer i
>> for i = 1 to UpperBound(pbdom_obj_array)
>> messagebox("Element is",string(pbdom_obj_array[i]))
>> next
>>
>> return latitude
>>
>> XML String is:
>>
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <kml xmlns="http://earth.google.com/kml/2.0"><Response>
>>  <name>2 Stanley Pl., Far Hills, NJ 07931</name>
>>  <Status>
>>    <code>200</code>
>>    <request>geocode</request>
>>  </Status>
>>  <Placemark id="p1">
>>    <address>2 Stanley Pl, Far Hills, NJ 07934, USA</address>
>> <AddressDetails Accuracy="8"
>> xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryName
>> Code>US</CountryNameCode><CountryName>USA</CountryName><Administrative
>> Area><AdministrativeAreaName>NJ</AdministrativeAreaName><SubAdministra
>> tiveArea><SubAdministrativeAreaName>Morris</SubAdministrativeAreaName>
>> <Locality><LocalityName>Far
>> Hills</LocalityName><Thoroughfare><ThoroughfareName>2 Stanley
>> Pl</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>0793
>> 4</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></
>> AdministrativeArea></Country></AddressDetails>    <ExtendedData>
>> <LatLonBox north="40.7429886" south="40.7366934" east="-74.6749984"
>> west="-74.6812936" />    </ExtendedData>
>> <Point><coordinates>-74.6781460,40.7398410,0</coordinates></Point>
>> </Placemark> </Response></kml> 


0
Paul
3/2/2010 2:02:29 AM
On 2/03/2010 1:02 PM, Paul Murray wrote:
> Thanks, Art!!
>
> There are soooo many uses and means of implementing XML in this forum that I
> find it difficult to find what I am looking for...
>
> I will try GetChildElement (I am only looking for one and it does not
> repeat).
>
> I guess I thought that XML had been around long enough that you could simply
> feed in the XML and execute a function like:
>
> variable = gettext(<coordinates>).

you will need to roll your own to recursively find all the elements or a 
method to return the first found. Its not that hard to implement 
although it is poor on performance.

alternatively if you are in the .net world you can use the system XML 
classes and use the selectsinglenode method with xpath which makes 
finding nodes very easy and quick. I can provide some help here if you 
want to go this path.

a.


>
> Thanks again for your help!
>
> Paul
>
>
> "Arthur Hefti"<arthur@catsoft.ch>  wrote in message
> news:4b8b4a8d@forums-1-dub...
>> Paul
>>
>> You could use GetChildElement/GetChildElements to find the coordinates
>> element. Before this function existed in PB I wrote a recursive
>> function to find an element. I used GetContent to retrieve the array of
>> elements of the first level, checked for type element, if found checked
>> for the name of the element I'm searching. If not found, I pass the
>> element to the function again.
>>
>> Regards
>> Arthur
>> --
>>
>>
>>
>> Paul Murray wrote:
>>
>>> Greetings All,
>>>
>>> I have an XML string that has an element called<coordinates>.
>>>
>>> I want to get the value of<coordinates>, but I can't seem to figure
>>> out how to reference it directly.
>>>
>>> Below is the code for my function and the XML string...
>>>
>>> If someone can point me in the right direction, I would appreciate it.
>>>
>>> Thanks!!
>>>
>>> Paul
>>>
>>> Argument is string as 'strXML'
>>> Return value is real as 'latitude'
>>>
>>> messagebox("The passed string is",strXML)
>>>
>>> real latitude
>>>
>>> PBDOM_Builder pbdom_bldr
>>> pbdom_document pbdom_doc
>>> PBDOM_OBJECT pbdom_obj_array[]
>>> PBDOM_Element pbdom_elem_root
>>>
>>> pbdom_bldr = Create PBDOM_Builder
>>> pbdom_doc = pbdom_bldr.BuildFromString(strXML)
>>> pbdom_elem_root = pbdom_doc.GetRootElement()
>>> boolean result
>>> result = pbdom_doc.getcontent(pbdom_obj_array)
>>>
>>> if result<>  true then
>>> messagebox("Failed to getcontent",string(result))
>>> else
>>> messagebox("Succeeded in getting getcontent",string(result))
>>> end if
>>>
>>>
>>> string coordinates_data
>>> //coordinates_data = pbdom_doc.12.gettext()
>>> coordinates_data = pbdom_elem_root.GetTextNormalize()
>>>
>>> messagebox("coordinates_data",coordinates_data)
>>>
>>> messagebox("LowerBound",string(lowerbound(pbdom_obj_array)))
>>> messagebox("UpperBound",string(upperbound(pbdom_obj_array)))
>>>
>>> integer i
>>> for i = 1 to UpperBound(pbdom_obj_array)
>>> messagebox("Element is",string(pbdom_obj_array[i]))
>>> next
>>>
>>> return latitude
>>>
>>> XML String is:
>>>
>>> <?xml version="1.0" encoding="UTF-8" ?>
>>> <kml xmlns="http://earth.google.com/kml/2.0"><Response>
>>>   <name>2 Stanley Pl., Far Hills, NJ 07931</name>
>>>   <Status>
>>>     <code>200</code>
>>>     <request>geocode</request>
>>>   </Status>
>>>   <Placemark id="p1">
>>>     <address>2 Stanley Pl, Far Hills, NJ 07934, USA</address>
>>> <AddressDetails Accuracy="8"
>>> xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryName
>>> Code>US</CountryNameCode><CountryName>USA</CountryName><Administrative
>>> Area><AdministrativeAreaName>NJ</AdministrativeAreaName><SubAdministra
>>> tiveArea><SubAdministrativeAreaName>Morris</SubAdministrativeAreaName>
>>> <Locality><LocalityName>Far
>>> Hills</LocalityName><Thoroughfare><ThoroughfareName>2 Stanley
>>> Pl</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>0793
>>> 4</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></
>>> AdministrativeArea></Country></AddressDetails>     <ExtendedData>
>>> <LatLonBox north="40.7429886" south="40.7366934" east="-74.6749984"
>>> west="-74.6812936" />     </ExtendedData>
>>> <Point><coordinates>-74.6781460,40.7398410,0</coordinates></Point>
>>> </Placemark>  </Response></kml>
>
>

0
Adam
3/8/2010 1:20:36 AM
Reply:

Similar Artilces:

How do I get XML elements having same name in a XML node
XML Code: <questions> <question> <q>What is your number?</q> <answer>3</answer> <answer>5</answer> <answer>9</answer> </question> <question> <q>In what state did you studied?</q> <answer>Indiana</answer> <answer>Arkansas</answer> <answer>Tennessee</answer> </question> </questions> Code:  XmlDocument doc = new XmlDocument(); doc.Load(XMLFilePath); //PAth to the XML file XmlEl...

Getting text from an XML file using XML::Twig
--f46d044285f20c454904b338c7a6 Content-Type: text/plain; charset=ISO-8859-1 Dear Beginners List, My code is based on an example from the XML::Twig documentation. I want to capture the text of a couple elements that have descendant elements and put this text in separate variables (one for each element's text). The problem in the code example is that all the text of the lower elements is returned in a 'print'. So to illustrate: <title>text # I want this piece of text saved in one variable <subtitle>more text # and this pie...

superreview requested: [Bug 282186] sync xpfe text.xml with toolkit text.xml : [Attachment 221205] (Cv1-XPFE) <text.xml>
Serge GAUTHERIE <gautheri@noos.fr> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 282186: sync xpfe text.xml with toolkit text.xml https://bugzilla.mozilla.org/show_bug.cgi?id=282186 Attachment 221205: (Cv1-XPFE) <text.xml> https://bugzilla.mozilla.org/attachment.cgi?id=221205&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> This part comes from bug 280065 and followups. Untested. ...

XMl to XML
Hello,   I retrieved an XML from the dataset which retrieves data from the table in the database. I need to present the data  in a different structure. Is XSLT the way or are there any other options. please let me know. Thanks!! Yes XSLT is a good choice to convert xml file to other forms. You can take a look at XSLT Tutorial.Sincerely,Young Fang...

XML in, XML out
Hi All (and a happy holiday to those that will get a break), I am trying to read in an XML file of addresses. I need to remove all the address data from the file where code =~ /^000/ (there are none in the example data below). I need to reproduce that data 'as is', so I need to honour the tag structure, although the order of the tags doesn't need to be honoured. I have been trying to use XML::Simple and I had a go with XML::Smart but I haven't been able to get the results I want. My best effort is below (with XML::Simple). There are a couple of differences ...

Creating an XML Element from XML string?
Before a form is submitted back to the server I create an XML representation of the current state of a certain ListBox and store it in a hidden field, as it appears that a Listbox when manipulated on the client does not return it's state back to the server correctly.In each item's value property in the listbox there is already stored an XML representation of that item (populated from the Server when the page was created).  The problem I am encountering is how to create an XML element from that XML string stored in the value property.  I know I can parse through the XML string and b...

XML Question using XML::Element
I am fresh to the new glorious World of XML, and trying to figure out how this stuff melds together with perl. I found http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html could somebody look over my code analysis and tell me if I am (nearly) right? require "files/camelid_links.pl"; # Needs the specified file to work. my %camelid_links = get_camelid_data(); # Some function that greates the Hash (see section the Hash). my $root = XML::Element->new('html'); # Creates the HTML Frame <html></html>. my $body = XML::Element->new('body'...

how to get elements in such a XML
Dear Experts: I have a XML document in a string variable, like following: <feed xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> <title>the result of 9787115166890</title> <opensearch:startIndex>1</opensearch:startIndex> <opensearch:itemPerPage>10</opensearch:itemPerPage> <opensearch:totalResults>1</opensearch:totalResults> <entry> <id>http:...

superreview canceled: [Bug 282186] sync xpfe text.xml with toolkit text.xml
neil@parkwaycc.co.uk <neil@httl.net> has canceled Serge Gautherie <sgautherie.bz@free.fr>'s request for superreview: Bug 282186: sync xpfe text.xml with toolkit text.xml https://bugzilla.mozilla.org/show_bug.cgi?id=282186 Attachment 221205: (Cv1-XPFE) <text.xml> https://bugzilla.mozilla.org/attachment.cgi?id=221205&action=edit ...

When I get .XML document with Request.Form["xml"].ToString(); it gets error.
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(Request.Form["xml"].ToString());  I want system doesn't interrupt the code execution. How can I do system doesn't give error message?  Thanks.  Error Message  A potentially dangerous Request.Form value was detected from the client (xml="...8859-9" ?><BORCELIK><Tarih>09/...").  ...

XML::Parser XML::DOM XML::XSLT
------_=_NextPart_001_01C6E0D0.3E27D77A Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Hi Craig and fellow VMS Perlers, You last wrote about this Fri 3/16/2001 11:24 AM, not counting your very helpful comments on Eisner/Decuserve more recently. One of my colleagues sent me an email requesting that I make XML::XSLT=20 available on VMS. perl 5.8.6, VMS 7.3-2, DECC 7.1 latest ACRTL (version 3) on Alpha XML::XSLT (version 0.48) depends on XML::Parser (version 2.34). This depends on expat (version 2.0.0). I built expat a...

Get XML content using XML::Twig
Hello all, I'm trying to parse the XML using XML::Twig Module as my XML could be very large to handle using XML::Simple. Please help me out of how to print the values based on the following... <B>get the values of Sender, Receiver</B> <B>get the FileType. In this case possible values are InitTAP,FatalRAP,ReTxTAP</B> <CODE> get the values of Sender, Receiver get the FileType. In this case possible values are InitTAP,FatalRAP,ReTxTAP </CODE> <P>Here is the XML content....</P> <CODE> <?xml version="1.0"...

Re: Import xml file in xml Element
Here, I got one question, you might be able to help me.  Is it possible to import xml file in xml element? For example: <store>  <book>     <name>Harry Potter</name>     <version>5</version>     <publish>2007</publish>     <details>c:\actress.xml</details>   </book></store> -- c:\actress.xml <harry> <actor>Daniel Radcliffe</actor> <age>18</age> </harry> <Hermione&...

Get info from PropertyValueString
Hi All, I have inherited a project written by someone who was a much better programmer than myself and would appreciate some help in the right direction as I am way out of my depth. The problem is I need info about the logged in users profile in the asp_netProfile table which contains a field "PropertyValueString" with xml (nText field) in that looks like this:  <?xml version="1.0" encoding="utf-16"?><ProfileObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"...

Web resources about - Get Text from XML Element - sybase.powerbuilder.xml

Éléments de géométrie algébrique - Wikipedia, the free encyclopedia
The Éléments de géométrie algébrique ("Elements of Algebraic Geometry ") by Alexander Grothendieck (assisted by Jean Dieudonné ), or EGA for ...

Boag’s immerses in the elements
A SYMPHONY created by the Tasmanian elements will be the star of brewer James Boag’s latest marketing campaign.

Tony Blair apologises for aspects of Iraq invasion, admits 'elements of truth' it was connected to IS ...
... of Iraq. Britain's former prime minister Tony Blair has apologised for certain aspects of the 2003 invasion of Iraq, adding there were "elements ...

‘Future teardown’ of a Google self-driving car shows us who could be making the various elements
While it seems near-certain that Google plans a full-scale commercial rollout of its self-driving cars, it has also made clear on several occasions ...

‘Future teardown’ of an Apple Car shows us who could be making the various elements
... massively more complex than making consumer electronics devices. Apple will therefore be looking for partners to pull together different elements ...

Elements of a Successful Instagram Ad
With advertising beginning to surge on Instagram since it was made available to all brands at the end of September, what goes into the creation ...

New model explains how the Earth stole the Moon’s lighter elements
... by the idea that the two formed from the shared debris of a collision between the early Earth and a Mars-sized body. But there are some elements ...

Human element is key to effective use of analytics
... a strong enough differentiating factor among organizations companies must invest in people and recognize the importance of the human element ...

Adobe Photoshop Elements & Premiere Elements 14: Half off on Amazon for one day only
... brand is synonymous with quality. While Adobe software can often be very pricey, Amazon is hosting a one-day-only sale on Adobe Photoshop Elements ...

An ex-Facebook exec just launched a $70 million fund for startups with 'data as a core element'
... devices. He says: "I don’t want to call ourselves a data fund, but a lot of the stuff we end up getting excited about has data as a core element. ...

Resources last updated: 11/28/2015 12:32:52 AM