Skip to content

Instantly share code, notes, and snippets.

@fenollp
Created November 25, 2015 16:09
Show Gist options
  • Save fenollp/32380c9d263570bc1c8a to your computer and use it in GitHub Desktop.
Save fenollp/32380c9d263570bc1c8a to your computer and use it in GitHub Desktop.
wh_util:get_xml_value/2
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<soap:Body>
<SearchTelephoneNumbersResponse xmlns='http://www.bandwidth.com'>
<SearchTelephoneNumbersResult>
<a>
text out
<mytext ishere="text in"/>
</a>
<TelephoneNumber id="1">
<DateLastModified>2015-06-18T09:55:09.513</DateLastModified>
<DateCreated>2015-06-18T09:55:09.513</DateCreated>
<CreatedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</CreatedBy>
<LastModifiedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</LastModifiedBy>
<Obsolete>false</Obsolete>
<TelephoneNumberID>003EEE26-3D30-4C03-8322-EA5929B373B1</TelephoneNumberID>
<TelephoneNumberType>Tollfree</TelephoneNumberType>
<TelephoneNumberRequisitionNumber>0</TelephoneNumberRequisitionNumber>
<VendorID>bb03ff9a-7649-4336-a1c8-fab6156726d8</VendorID>
<VendorName>Bandwidth.com powered by Level 3</VendorName>
<GatewayID>46e8a2f6-7583-494d-877d-4a0597de3e7e</GatewayID>
<GatewayName>Default Gateway</GatewayName>
<Status>Available</Status>
<PreviousStatus>Available</PreviousStatus>
<TelephoneNumberIndicator>Business</TelephoneNumberIndicator>
<Country>
<DateLastModified>2006-05-30T20:30:31.917</DateLastModified>
<DateCreated>2006-05-30T20:30:31.917</DateCreated>
<CreatedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</CreatedBy>
<LastModifiedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</LastModifiedBy>
<Obsolete>false</Obsolete>
<ID>95fda5f2-fbfa-40a5-95e7-671e51e9d1b4</ID>
<Name>United States</Name>
<IsoAlpha2Code>US</IsoAlpha2Code>
<IsoAlpha3Code>USA</IsoAlpha3Code>
<IsoNumeric3Code>840</IsoNumeric3Code>
<DialingCode>1</DialingCode>
<IsAvailable>true</IsAvailable>
</Country>
<AreaCode>866</AreaCode>
<Prefix>837</Prefix>
<Line>8193</Line>
<UseLegacyGatewayProvisioning>false</UseLegacyGatewayProvisioning>
<IsBWCRespOrg>false</IsBWCRespOrg>
</TelephoneNumber>
<TelephoneNumber id="2">
<DateLastModified>2015-06-18T09:54:10.197</DateLastModified>
<DateCreated>2015-06-18T09:54:10.197</DateCreated>
<CreatedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</CreatedBy>
<LastModifiedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</LastModifiedBy>
<Obsolete>false</Obsolete>
<TelephoneNumberID>005ADE20-995A-4065-9331-0C7BC3B16B9B</TelephoneNumberID>
<TelephoneNumberType>Tollfree</TelephoneNumberType>
<TelephoneNumberRequisitionNumber>0</TelephoneNumberRequisitionNumber>
<VendorID>bb03ff9a-7649-4336-a1c8-fab6156726d8</VendorID>
<VendorName>Bandwidth.com powered by Level 3</VendorName>
<GatewayID>46e8a2f6-7583-494d-877d-4a0597de3e7e</GatewayID>
<GatewayName>Default Gateway</GatewayName>
<Status>Available</Status>
<PreviousStatus>Available</PreviousStatus>
<TelephoneNumberIndicator>Business</TelephoneNumberIndicator>
<Country>
<DateLastModified>2006-05-30T20:30:31.917</DateLastModified>
<DateCreated>2006-05-30T20:30:31.917</DateCreated>
<CreatedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</CreatedBy>
<LastModifiedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</LastModifiedBy>
<Obsolete>false</Obsolete>
<ID>95fda5f2-fbfa-40a5-95e7-671e51e9d1b4</ID>
<Name>United States</Name>
<IsoAlpha2Code>US</IsoAlpha2Code>
<IsoAlpha3Code>USA</IsoAlpha3Code>
<IsoNumeric3Code>840</IsoNumeric3Code>
<DialingCode>1</DialingCode>
<IsAvailable>true</IsAvailable>
</Country>
<AreaCode>866</AreaCode>
<Prefix>796</Prefix>
<Line>4634</Line>
<UseLegacyGatewayProvisioning>false</UseLegacyGatewayProvisioning>
<IsBWCRespOrg>false</IsBWCRespOrg>
</TelephoneNumber>
<TelephoneNumber id="3">
<DateLastModified>2015-06-18T09:54:10.197</DateLastModified>
<DateCreated>2015-06-18T09:54:10.197</DateCreated>
<CreatedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</CreatedBy>
<LastModifiedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</LastModifiedBy>
<Obsolete>false</Obsolete>
<TelephoneNumberID>010A55D9-4EFB-45D1-A67D-341C74FE295B</TelephoneNumberID>
<TelephoneNumberType>Tollfree</TelephoneNumberType>
<TelephoneNumberRequisitionNumber>0</TelephoneNumberRequisitionNumber>
<VendorID>bb03ff9a-7649-4336-a1c8-fab6156726d8</VendorID>
<VendorName>Bandwidth.com powered by Level 3</VendorName>
<GatewayID>46e8a2f6-7583-494d-877d-4a0597de3e7e</GatewayID>
<GatewayName>Default Gateway</GatewayName>
<Status>Available</Status>
<PreviousStatus>Available</PreviousStatus>
<TelephoneNumberIndicator>Business</TelephoneNumberIndicator>
<Country>
<DateLastModified>2006-05-30T20:30:31.917</DateLastModified>
<DateCreated>2006-05-30T20:30:31.917</DateCreated>
<CreatedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</CreatedBy>
<LastModifiedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</LastModifiedBy>
<Obsolete>false</Obsolete>
<ID>95fda5f2-fbfa-40a5-95e7-671e51e9d1b4</ID>
<Name>United States</Name>
<IsoAlpha2Code>US</IsoAlpha2Code>
<IsoAlpha3Code>USA</IsoAlpha3Code>
<IsoNumeric3Code>840</IsoNumeric3Code>
<DialingCode>1</DialingCode>
<IsAvailable>true</IsAvailable>
</Country>
<AreaCode>866</AreaCode>
<Prefix>676</Prefix>
<Line>2182</Line>
<UseLegacyGatewayProvisioning>false</UseLegacyGatewayProvisioning>
<IsBWCRespOrg>false</IsBWCRespOrg>
</TelephoneNumber>
<TelephoneNumber id="4">
<DateLastModified>2015-06-18T09:54:10.197</DateLastModified>
<DateCreated>2015-06-18T09:54:10.197</DateCreated>
<CreatedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</CreatedBy>
<LastModifiedBy>53CDB6AB-5D73-4230-B352-EA06A3A3C64E</LastModifiedBy>
<Obsolete>false</Obsolete>
<TelephoneNumberID>0124BAD9-457E-4AF1-B4A3-C0FBDA3ABF6D</TelephoneNumberID>
<TelephoneNumberType>Tollfree</TelephoneNumberType>
<TelephoneNumberRequisitionNumber>0</TelephoneNumberRequisitionNumber>
<VendorID>bb03ff9a-7649-4336-a1c8-fab6156726d8</VendorID>
<VendorName>Bandwidth.com powered by Level 3</VendorName>
<GatewayID>46e8a2f6-7583-494d-877d-4a0597de3e7e</GatewayID>
<GatewayName>Default Gateway</GatewayName>
<Status>Available</Status>
<PreviousStatus>Available</PreviousStatus>
<TelephoneNumberIndicator>Business</TelephoneNumberIndicator>
<Country>
<DateLastModified>2006-05-30T20:30:31.917</DateLastModified>
<DateCreated>2006-05-30T20:30:31.917</DateCreated>
<CreatedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</CreatedBy>
<LastModifiedBy>d245df4b-0d34-4010-bff0-64b9ffa2ba73</LastModifiedBy>
<Obsolete>false</Obsolete>
<ID>95fda5f2-fbfa-40a5-95e7-671e51e9d1b4</ID>
<Name>United States</Name>
<IsoAlpha2Code>US</IsoAlpha2Code>
<IsoAlpha3Code>USA</IsoAlpha3Code>
<IsoNumeric3Code>840</IsoNumeric3Code>
<DialingCode>1</DialingCode>
<IsAvailable>true</IsAvailable>
</Country>
<AreaCode>866</AreaCode>
<Prefix>786</Prefix>
<Line>8296</Line>
<UseLegacyGatewayProvisioning>false</UseLegacyGatewayProvisioning>
<IsBWCRespOrg>false</IsBWCRespOrg>
</TelephoneNumber>
</SearchTelephoneNumbersResult>
</SearchTelephoneNumbersResponse>
</soap:Body>
</soap:Envelope>
28> E = fun (Path) -> Xs =xmerl_xpath:string(Path, element(1,xmerl_scan:string(binary_to_list(element(2,file:read_file("/Users/pete/_.xml")))))) , {[V || #xmlText{value=V} <- Xs], [V || #xmlAttribute{value=V} <- Xs]} end.
#Fun<erl_eval.6.54118792>
29> erlang:display(E("//TelephoneNumber/@id")).
{[],["1","2","3","4"]}
true
30> erlang:display(E("//TelephoneNumber/text()")).
{["\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n ","\n "],[]}
true
31> erlang:display(E("//TelephoneNumber/@id/text()")).
{[],[]}
true
32>
@fenollp
Copy link
Author

fenollp commented Nov 25, 2015

xmlText{} and #xmlAttribute{} seem mutually exclusive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment