Dom parsing with a attribute name with a number sign

L

lars.charmer

Hey

I am trying to parse some xml from a ArcIms service, and in the result
xml, one of the attribute names contain a number sign, like #. When I
trying to parse this xml I get the folowing exception:
[Fatal Error] :1:49: Element type "FIELDS" must be followed by either
attribute specifications, ">" or "/>".
Exception in thread "main" org.xml.sax.SAXParseException: Element type
"FIELDS" must be followed by either attribute specifications, ">" or
"/>".


I have made this small demo program to illustratet my problem:

<java program>
import java.io.ByteArrayInputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

import org.xml.sax.InputSource;

public class Demo{

public static void main(String[] args) throws Exception {

String xmlString = "<?xml version='1.0' encoding='UTF-8' ?>"+
"<FIELDS #SHAPE#='[Geometry]' />";

byte[] byteArr =xmlString.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(byteArr);

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

InputSource inputSource = new InputSource(bais);
Document document = builder.parse(inputSource);
}
}
</java>

What can I do to solve this problem.
 
A

Andrew Thompson

I am trying to parse some xml from a ArcIms service, and in the result
xml, one of the attribute names contain a number sign, like #. When I
trying to parse this xml I get the folowing exception:
[Fatal Error] :1:49: Element type "FIELDS" must be followed by either
attribute specifications, ">" or "/>".
Exception in thread "main" org.xml.sax.SAXParseException: Element type
"FIELDS" must be followed by either attribute specifications, ">" or
"/>". ....
String xmlString = "<?xml version='1.0' encoding='UTF-8' ?>"+
"<FIELDS #SHAPE#='[Geometry]' />";

This suggest to me that '#' is not a valid character for
XML attributes.
What can I do to solve this problem.

Use valid XML?

Andrew T.
 
L

lars.charmer

Easy for you to say. This service/server have returned this kind off
response for the last 6 year, and don't think that ESRI (the company
who's making the ArcIms server), is goving to change it just for me.

Andrew Thompson skrev:
 
L

lars.charmer

(e-mail address removed) skrev:
Easy for you to say. This service/server have returned this kind off
response for the last 6 year, and don't think that ESRI (the company
who's making the ArcIms server), is goving to change it just for me.

Andrew Thompson skrev:

Okay it is easy(Sorry Andrew T.). Esri do support valid XML, I just
have to specify you want that. They have a attribute callede outmode
and that should have the value "newxml". But what was they suppose to
when they introduced a invalid XML, and every body was using it,
becaurse that was the default value.

Best regards
Lars Charmer Jørgensen
 
A

Andrew Thompson

(e-mail address removed) skrev:

Huh? Your decision to put that comment - floating at
the top, out of context, makes it hard to understand
what you are referring to.

Also - where did the extra indents come from?

The use of '>' preceding your text makes it appear
as if that first paragraph was *quoted* by you.
....
Okay it is easy(Sorry Andrew T.).

I never implied it was easy. (And I don't see the need for apologies.)
..Esri do support valid XML, I just
have to specify you want that.

I want world peace. This is just an interesting diversion.

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top