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

Discussion in 'Java' started by Ed, Aug 1, 2007.

  1. Ed

    Ed Guest

    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) {
    }
    Ed, Aug 1, 2007
    #1
    1. Advertising

  2. 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Aug 2, 2007
    #2
    1. Advertising

  3. Ed

    Ed Guest

    On Aug 1, 4:00 pm, Arne Vajhøj <> 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
    Ed, Aug 2, 2007
    #3
  4. 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 <> 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Aug 2, 2007
    #4
  5. Ed

    Ed Guest

    On Aug 1, 4:37 pm, Arne Vajhøj <> wrote:
    > Ed wrote:
    > > On Aug 1, 4:00 pm, Arne Vajhøj <> 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
    Ed, Aug 2, 2007
    #5
  6. "Arne Vajhøj" <> wrote in message
    news:46b11938$0$90263$...
    >> 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.
    Mike Schilling, Aug 2, 2007
    #6
  7. Re: DocumentBuilder object is not able to parse a XML String whichhas a nodename which contains forward slash!

    Mike Schilling wrote:
    > "Arne Vajhøj" <> wrote in message
    > news:46b11938$0$90263$...
    >>> 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Aug 2, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page