Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Ed - 01 Aug 2007 22:37 GMT
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) {
}
Arne Vajhøj - 02 Aug 2007 00:00 GMT
> 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.
[quoted text clipped - 17 lines]
> 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
Ed - 02 Aug 2007 00:17 GMT
On Aug 1, 4:00 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
> > 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.
[quoted text clipped - 30 lines]
>
> 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
Arne Vajhøj - 02 Aug 2007 00:37 GMT
>>> 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.
[quoted text clipped - 25 lines]
> 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
Ed - 02 Aug 2007 01:47 GMT
On Aug 1, 4:37 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
> > On Aug 1, 4:00 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
> >>> In my code below, I do have a XML String which has NodeName made of
[quoted text clipped - 36 lines]
>
> Arne

Arne, that's a good point!
Thanks!
Ed
Mike  Schilling - 02 Aug 2007 05:05 GMT
>> 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.

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.
Arne Vajhøj - 02 Aug 2007 16:29 GMT
Mike Schilling wrote:
>>> I need to keep that Forward Slash as it is in the NodeName.
>>> Is there away to make the DocumentBuilder object, not to complain
[quoted text clipped - 4 lines]
> applied to XML documents (that they conform to a DTD or schema), and that's
> not what you mean here.

True.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.