Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward slash! (http://www.velocityreviews.com/forums/t526312-documentbuilder-object-is-not-able-to-parse-a-xml-string-which-has-a-nodename-which-contains-forward-slash.html)

Ed 08-01-2007 09:37 PM

DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward slash!
 
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?= 08-01-2007 11:00 PM

Re: DocumentBuilder object is not able to parse a XML String whichhas a nodename which contains forward slash!
 
Ed 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.
>
> 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



Ed 08-01-2007 11:17 PM

Re: DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward slash!
 
On Aug 1, 4:00 pm, Arne Vajh°j <a...@vajhoej.dk> wrote:
> Ed 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.

>
> > 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


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?= 08-01-2007 11:37 PM

Re: DocumentBuilder object is not able to parse a XML String whichhas a nodename which contains forward slash!
 
Ed wrote:
> On Aug 1, 4:00 pm, Arne Vajh°j <a...@vajhoej.dk> wrote:
>> Ed 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.
>>> 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");
>>
>> ?

>
> 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

Ed 08-02-2007 12:47 AM

Re: DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward slash!
 
On Aug 1, 4:37 pm, Arne Vajh°j <a...@vajhoej.dk> wrote:
> Ed wrote:
> > On Aug 1, 4:00 pm, Arne Vajh°j <a...@vajhoej.dk> wrote:
> >> Ed 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.
> >>> 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");

>
> >> ?

>
> > 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


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


Mike Schilling 08-02-2007 04:05 AM

Re: DocumentBuilder object is not able to parse a XML String which has a nodename which contains forward slash!
 
"Arne Vajh°j" <arne@vajhoej.dk> wrote in message
news:46b11938$0$90263$14726298@news.sunsite.dk...
>> 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.



=?ISO-8859-1?Q?Arne_Vajh=F8j?= 08-02-2007 03:29 PM

Re: DocumentBuilder object is not able to parse a XML String whichhas a nodename which contains forward slash!
 
Mike Schilling wrote:
> "Arne Vajh°j" <arne@vajhoej.dk> wrote in message
> news:46b11938$0$90263$14726298@news.sunsite.dk...
>>> 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.


True.

Arne


All times are GMT. The time now is 10:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.