Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attribute problem - using &id in attribute value

Status
Not open for further replies.

phknox

Programmer
Dec 4, 2003
5
US
I have an element with attributes as shown:

<item_name avail=&quot;false&quot; url=&quot; One-page, dated pages for planner</item_name>

I use JDOM to read and write my xml files. However, I need to manually modify an xml file sometimes. When I use Textpad or Notepad and save the file, I get the following error when trying to read the file.

Error on line 7 of document file:/C:/Program%20Files/Apache%20Group/Tomcat%204.1/webapps/christmas_app/WEB-INF/info.xml: The reference to entity &quot;id&quot; must end with the ';' delimiter.

What do I need to do to modify the file and it still be useable?

Thanks,
phknow
 
Apparently it's trying to interpret the ampersands in your URL's query string as entity references.

Try changing the &quot;&&quot;s to &quot;%26&quot;s. (E.g., change &quot;&id&quot; to &quot;%26id&quot;.) The XML parser won't screw with it, and the query string should URLDecode properly.

Let us know whether that works.
 
Thanks harebrain....it partially works. At least I can read the xml file now. Apparently, though, the urls aren't decoding properly because the links do not work. In the xml file, I replaced the & with %26. My servlet can now read the xml file and build the webpage. When I mouse over the links in my webpage, they look fine (ie, %26 has been decoded back to &). However, the links don't work. I get an error page depending on how the linked site is setup.

I still don't understand what textpad or notepad is doing when it saves the file. The xml file works fine with the ampersands as long as JDOM reads and writes it. However, if I modify it in textpad, the & become unreadable. I am saving the file with utf-8 encoding.

Any other thoughts?

thanks,
phknox
 
ok, I found a fix....still not sure what's going on, but at least it's working now. If I replace '&' with '&amp;' the webapp works fine and the url's work, too.

phknox
 
uh oh.....it seems my fix does not show correctly (I guess I should have Previewed the post before I submitted). The fix is '& amp;' without the space.

phknox
 
Oddly, your solution is the one I would have tried first myself, replacing &'s with the general entity for ampersand. I'd have expected that to work with character data, but with attibute values (such as you have) it often seems that all bets are off.

(I'm looking at Windows 2000...) As for Notepad, are you sure UTF-8 is the right encoding for your JDOM parser? What does the XML declaration look like in your file?
 
I'm using the default encoding for JDOM which is UTF-8. The declaration is:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>

phknox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top