Skip to content

Instantly share code, notes, and snippets.

@mnewt
Created February 11, 2016 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnewt/af16a07f513a3d12bd41 to your computer and use it in GitHub Desktop.
Save mnewt/af16a07f513a3d12bd41 to your computer and use it in GitHub Desktop.
clj-xpath map issue with namespaces removed
(ns testing
(:require [clj-xpath.core :as xp]))
(def ^:dynamic xml-doc
(slurp "xml-test.xml"))
(xp/with-namespace-context (xp/xmlnsmap-from-root-node xml-doc)
(xp/$x "//Person" xml-doc))
(xp/with-namespace-context (xp/xmlnsmap-from-root-node xml-doc)
(xp/$x "//Person/PersonName/PersonGivenName" xml-doc))
(xp/with-namespace-context (xp/xmlnsmap-from-root-node xml-doc)
(xp/$x:text "./PersonName/PersonGivenName"
(first (xp/$x "//Person" xml-doc))))
; => "Bob"
(xp/with-namespace-context (xp/xmlnsmap-from-root-node xml-doc)
(map
#(xp/$x:text "./PersonName/PersonGivenName" %)
(xp/$x "//Person" xml-doc)))
; => ("Bob")
<?xml version="1.0" encoding="UTF-8"?>
<doPublish
xmlns:ulex="http://ulex.gov/ulex/2.0"
xmlns:ulexpd="http://ulex.gov/publishdiscover/2.0"
xmlns:ulexcodes="http://ulex.gov/codes/2.0"
xmlns:ulexlib="http://ulex.gov/library/2.0"
xmlns:j="http://niem.gov/niem/domains/jxdm/4.1"
xmlns:nc="http://niem.gov/niem/niem-core/2.0"
xmlns:em="http://niem.gov/niem/domains/emergencyManagement/2.1"
xmlns:fs="http://niem.gov/niem/domains/familyServices/2.1"
xmlns:im="http://niem.gov/niem/domains/immigration/2.1"
xmlns:scr="http://niem.gov/niem/domains/screening/2.1"
xmlns:s="http://niem.gov/niem/structures/2.0"
xmlns:lexs="http://lexs.gov/lexs/4.0"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:lexsdigest="http://lexs.gov/digest/4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ulex.gov/publishdiscover/2.0 ../../xsd/ulex.gov/ulex-publish-discover/2.0/ulex-publish-discover.xsd">
<!--======================= Person with Enforcement Official Role =======================-->
<EntityPerson>
<Metadata s:id="MOff1">
<SourceIDText>Per12345</SourceIDText>
</Metadata>
<Person s:id="Off1" s:metadata="MOff1">
<PersonName>
<PersonGivenName>Bob</PersonGivenName>
<PersonSurName>Evans</PersonSurName>
</PersonName>
</Person>
<EnforcementOfficial>
<RoleOfPersonReference s:ref="Off1"/>
<EnforcementOfficialBadgeIdentification>
<IdentificationID>AGENCY3700</IdentificationID>
</EnforcementOfficialBadgeIdentification>
</EnforcementOfficial>
</EntityPerson>
</doPublish>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment