Robert Klemme wrote:
option that I can set on the puts method that will solve it. Hopefully
<prefix>Find related product support and help in</prefix>
puts "Did XPATH match any profile elements?"
Did XPATH match any profile elements?
Support but I don't have a clue where the _Link is coming from?
Rule one of anything like this is to remove each element from the XML file
one by one and see which one is breaking you. In this case you will find
that it's the link element because you are using ampersands in the URL. See
here
http://www.w3.org/TR/xhtml1/guidelines.html#C_12
One more hint: when posting things like this it is best to provide a
_complete_ example. From the XPath given it is clear that something
must be missing (there are no "product" tags). It's pretty easy with
REXML:
robert@fussel ~
$ cat x.rb
require 'rexml/document'
data = REXML::Document.new <<'DOC'
<product>
<profile>
<support>
<title>eSupport</title>
<prefix>Find related product support and help in</prefix>
<link>
http://www.somecompany.com/US/perl/model-home.pl?XID=M:products:crmportal&LOC=3&mdl=someModel
</link>
</support>
</profile>
</product>
DOC
data.elements.each("product/profile/support"){|element|
element.elements.each() do |child|
puts "Did XPATH match any profile elements?"
puts child.text
end
}
Which on my box produces:
robert@fussel ~
$ ruby19 x.rb
/usr/local/lib/ruby19/1.9.1/rexml/parsers/treeparser.rb:95:in `rescue in
parse': #<RuntimeError: Illegal character '&' in raw string "
(REXML::ParseException)
http://www.somecompany.com/US/perl/model-home.pl?XID=M:products:crmportal&LOC=3&mdl=someModel
">
/usr/local/lib/ruby19/1.9.1/rexml/text.rb:155:in `block in check'
/usr/local/lib/ruby19/1.9.1/rexml/text.rb:153:in `scan'
/usr/local/lib/ruby19/1.9.1/rexml/text.rb:153:in `check'
/usr/local/lib/ruby19/1.9.1/rexml/text.rb:125:in `parent='
/usr/local/lib/ruby19/1.9.1/rexml/parent.rb:19:in `add'
/usr/local/lib/ruby19/1.9.1/rexml/parsers/treeparser.rb:45:in `parse'
/usr/local/lib/ruby19/1.9.1/rexml/document.rb:228:in `build'
/usr/local/lib/ruby19/1.9.1/rexml/document.rb:43:in `initialize'
x.rb:4:in `new'
x.rb:4:in `<main>'
...
Illegal character '&' in raw string "
http://www.somecompany.com/US/perl/model-home.pl?XID=M:products:crmportal&LOC=3&mdl=someModel
"
Line: 8
Position: 221
Last 80 unconsumed characters:
</link>
from
/usr/local/lib/ruby19/1.9.1/rexml/parsers/treeparser.rb:20:in `parse'
from /usr/local/lib/ruby19/1.9.1/rexml/document.rb:228:in
`build'
from /usr/local/lib/ruby19/1.9.1/rexml/document.rb:43:in
`initialize'
from x.rb:4:in `new'
from x.rb:4:in `<main>'
robert@fussel ~
$
How did you manage to get REXML parse this?
Kind regards
robert
That's really interesting. This works, but just gives that odd output
like this: ???Product_Support_Link_Title???
Here is exactly what I'm doing:
I have XML that looks like this:
<product>
<profile>
<support>
<title>eSupport</title>
<prefix>Find related product support and help in</prefix>
<link>
http://www.somecompany.com/US/perl/model-home.pl?XID=M:products:crmportal&LOC=3&mdl=someModel
</link>
</support>
</profile>
</product>
And I'm walking it using REXML like this:
data.elements.each("product/profile/support"){|element|
element.elements.each() do |child|
puts "Did XPATH match any profile elements?"
puts child.text
end
}
Where data is the body of an HTTP GET request to a ReST-ish web service
(I can't post the endpoint of the web service since it's an internal
server)
I'm invoking the web service from a file called product.rb using the
Rails command script/runner app/models/product.rb
Maybe if I had done it all from IRB I would have gotten the illegal
character exception.
Is there any way that I can ignore the formatting rules for illegal
character and just take the whole text as a string? The article that
the first person posted said that the webservice should return links in
this format:
http://www.somecompany.com/US/perl/model-home.pl?XID=M:products:crmportal&LOC=3&mdl=someModel
using & instead of just & between arguments in the URL, which might
fly with REXML, but I'm not sure how to strip all that back off to make
it into a valid link since my browser doesn't know what to do with the
URL that has & between all the query parameters
Again, apologies if these are totally naive questions. I'm pretty new
at this...
Thanks,
David
···
On 30.11.2009 19:33, John W Higgins wrote:
--
Posted via http://www.ruby-forum.com/\.