1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

jsp/DOM question

Discussion in 'Software Development' started by tovachanah, Feb 12, 2007.

Thread Status:
Not open for further replies.
  1. tovachanah

    tovachanah Thread Starter

    Joined:
    Feb 15, 2006
    Messages:
    48
    i am running a program through jsp and getting the following msg from my programAdding

    new Node to XML message...
    invalid character in name

    the string 'new node to XML message is from the JSP'

    the invalid character in name is from the java program

    (short description of program: add a new node to an xml using DOM
    my program
    import com.skatestown.invoice.InvoiceChecker;

    import java.io.InputStream;

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;

    import org.w3c.dom.Attr;
    import org.w3c.dom.Element;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;

    /**
    * Add a new item node to the SkatesTown invoice using the DOM parser
    */
    public class InvoiceCheckerAdd implements InvoiceChecker {
    /**
    * Adds an itme node to the invoice
    * @DueDate: Feb 13, 2007
    * Program will create a new item node, fill the attributes and
    * attach it to the parent (order)
    *
    * @param invoiceXML Invoice XML document
    * @exception Exception Any exception returned during checking
    */
    public void checkInvoice(InputStream invoiceXML) throws Exception {

    // Obtain parser instance and parse the document
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(invoiceXML);

    // find the order node - the parent of the item
    Node orderNode = doc.getElementsByTagName("order").item(0);

    // create the item node and fill the attributes
    Element itemElement1 = doc.createElement("item");

    // Create and fill attributes of the new node
    Attr idAttr1 = doc.createAttribute("id");
    idAttr1.setValue("418-MC");

    Attr quantityAttr1 = doc.createAttribute("quantity");
    quantityAttr1.setValue("2000");

    Attr unitPriceAttr1= doc.createAttribute("unit price");
    unitPriceAttr1.setValue("0.00");

    // attatch the itemNode to the parent
    orderNode.appendChild(itemElement1);

    // create. fill and attach element item
    Element itemElement2 = doc.createElement("item");

    Attr idAttr2 = doc.createAttribute("id");
    idAttr2.setValue("499-MC");

    Attr quantityAttr2 = doc.createAttribute("quantity");
    quantityAttr2.setValue("20");

    Attr unitPriceAttr2= doc.createAttribute("unit price");
    unitPriceAttr2.setValue("20.00");

    orderNode.appendChild(itemElement2);


    } //end CheckInvoice

    } //end CheckInvoiceAdd

    )

    what is the invalid name referring to?
     
  2. Chicon

    Chicon

    Joined:
    Jul 29, 2004
    Messages:
    6,650
    Hi tovachanah,

    I don't think the attribute unit price is valid as XML doesn't accept tag names including space.
    I suggest you to have a try with unit_price.
     
  3. tovachanah

    tovachanah Thread Starter

    Joined:
    Feb 15, 2006
    Messages:
    48
    thank you...duh i should have looked at the xml
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/543509

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice