antchfx / xmlquery

xmlquery is Golang XPath package for XML query.
https://github.com/antchfx/xpath
MIT License
444 stars 89 forks source link

How to deal with spaces? #68

Closed GAZ082 closed 3 years ago

GAZ082 commented 3 years ago

Hey there. I have a record like this:

  <property>
    <Field name="prop_id">1593</Field>
    <Field name="prop_label">XA_PCV_P_11</Field>
    <Field name="prop_entity_type">1</Field>
    <Field name="prop_name">Opening pressure</Field>
    <Field name="Property ID">1593</Field>
    <Field name="Property Language">1</Field>
    <Field name="Text Entry Identifier">0</Field>
  </property>

And would like to get the Property Language value among others. How can I deal with the space "Property Language" has?

Currently Im trying this:

XMLPath := fmt.Sprintf(`/properties/property[Field[@name='prop_label']='%v']/Field[@name='prop_id' or @name='prop_name or @name="Property Language"']`, propLabel)

Already t ried with double quotes, three single quotes, etc. etc. to no avail.

Any tip? Thanks!

zhengchun commented 3 years ago

I didn't understand what you mean? The "//Field[@name='Property Language']" can works.

GAZ082 commented 3 years ago

Had single quotes missing, this worked:

    XMLPath := fmt.Sprintf(`/properties/property[Field[@name='prop_label']='%v']/Field[@name='prop_id' or @name='prop_name' or @name='Property Language']`, propLabel)