DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward

E

Ed

Hi All,

In my code below, I do have a XML String which has NodeName made of
two words split by a Forward Slash. Here it is: Number/Subsystem.

Is there anyway to make the DocumentBuilder object to parse XML String
and the Forward Slash, successfully?
I added this like of the code but it's not working:

XMLString = XMLString.replaceAll("Number/Subsystem","Number\"/
\"Subsystem");


Here is my code below:
------------------------------------


String XMLString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"

+"<computerPart>"
+"<Number/Subsystem>9</Number/Subsystem>"
+"</computerPart>";

XMLString = XMLString.replaceAll("Number/Subsystem","Number\"/
\"Subsystem");



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException ex7) {
}

Document XMLStringToDOM= null;
try {
XMLStringToDOM = builder.parse(new InputSource(new
StringReader(XMLString.toString())));
} catch (IOException ex8) {
} catch (SAXException ex8) {
}
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Ed said:
In my code below, I do have a XML String which has NodeName made of
two words split by a Forward Slash. Here it is: Number/Subsystem.

Is there anyway to make the DocumentBuilder object to parse XML String
and the Forward Slash, successfully?
I added this like of the code but it's not working:

XMLString = XMLString.replaceAll("Number/Subsystem","Number\"/
\"Subsystem");


Here is my code below:
------------------------------------


String XMLString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"

+"<computerPart>"
+"<Number/Subsystem>9</Number/Subsystem>"
+"</computerPart>";

XMLString = XMLString.replaceAll("Number/Subsystem","Number\"/
\"Subsystem");

/ is not valid in XML names - see:
http://www.w3.org/TR/REC-xml/#NT-Name

I do not understand your replace.

Do you mean:

XMLString = XMLString.replaceAll("Number/Subsystem","Number.Subsystem");

?

Arne
 
E

Ed

/ is not valid in XML names - see:
http://www.w3.org/TR/REC-xml/#NT-Name

I do not understand your replace.

Do you mean:

XMLString = XMLString.replaceAll("Number/Subsystem","Number.Subsystem");

?

Arne

Arne,

I need to keep that Forward Slash as it is in the NodeName.
Is there away to make the DocumentBuilder object, not to complain
about that Forward Slash, when parsing the XMLString?

Thanks!
Ed
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Ed said:
I need to keep that Forward Slash as it is in the NodeName.
Is there away to make the DocumentBuilder object, not to complain
about that Forward Slash, when parsing the XMLString?

I don't think so. It is not valid XML.


Replace it to something else.

And replace it back when you write it out again.

But it is actually wrong to call it XML when it is not.

Arne
 
E

Ed

I don't think so. It is not valid XML.

Replace it to something else.

And replace it back when you write it out again.

But it is actually wrong to call it XML when it is not.

Arne

Arne, that's a good point!
Thanks!
Ed
 
M

Mike Schilling

Arne Vajhøj said:
I don't think so. It is not valid XML.

Nitpick: it is not "well-formed" XML. "Valid" has a specific meaning when
applied to XML documents (that they conform to a DTD or schema), and that's
not what you mean here.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Mike said:
Nitpick: it is not "well-formed" XML. "Valid" has a specific meaning when
applied to XML documents (that they conform to a DTD or schema), and that's
not what you mean here.

True.

Arne
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top