Mercurial Hosting > luan
diff src/goodjava/xml/XmlParser.java @ 1468:35f3bfd4f51d
xml
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 14 Apr 2020 08:44:33 -0600 |
parents | 670b7d089699 |
children | 0246add03d11 |
line wrap: on
line diff
--- a/src/goodjava/xml/XmlParser.java Mon Apr 13 22:16:59 2020 -0600 +++ b/src/goodjava/xml/XmlParser.java Tue Apr 14 08:44:33 2020 -0600 @@ -58,6 +58,10 @@ attributes.put(attribute.getKey(),attribute.getValue()); } spaces(); + if( parser.match("/>") ) { + XmlElement element = new XmlElement(name,attributes); + return parser.success(element); + } required(">"); String s = string(name); if( s != null ) { @@ -76,6 +80,7 @@ int start = parser.begin(); while( parser.noneOf("<") ); String s = parser.textFrom(start); + s = decode(s); if( !endTag(name) ) return parser.failure(null); return parser.success(s); @@ -125,6 +130,7 @@ throw exception("unclosed attribute value"); } String value = parser.textFrom(start); + value = decode(value); parser.match(quote); Map.Entry<String,String> attribute = new AbstractMap.SimpleImmutableEntry<String,String>(name,value); return parser.success(attribute); @@ -169,4 +175,13 @@ return parser.anyOf(" \t\r\n"); } + private static String decode(String s) { + s = s.replace("<","<"); + s = s.replace(">",">"); + s = s.replace(""","\""); + s = s.replace("'","'"); + s = s.replace("&","&"); + return s; + } + }