Michael Glavassevich | 3 Dec 11:52 2009
Picon

Re: Null pointer exception during DocumentBuilder.parse(?file?);

This is a bug [1] that was fixed in Xerces-J back in 2007.

However, you are using Sun's implementation, not Apache Xerces-J. We cannot do anything about the problem you're having with this implementation as we have no influence over its codebase. You need to pursue this with the JDK vendor if you want a fix there.

Thanks.

[1] https://issues.apache.org/jira/browse/XERCESJ-977

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org

sri kumar <sri_kumar_4u <at> yahoo.co.in> wrote on 12/03/2009 04:50:50 AM:

> Hello All,
>
> I got null pointer exception while executing doc = builder.parse(xmlDataFile);
>
> There were few entities in the XML data file. On removing a
> particular entity, i was able to parse the file successfully
>
> The entity was some thing like this
>
> <!ENTITY SAMPLE.TIF SYSTEM "SAMPLE.TIF" NDATA TIF>
>
> What could be the reason?
>
> Here is the code:
>
> DocumentBuilderFactory aFactory = DocumentBuilderFactory.newInstance();
> aFactory.setValidating(false);
> aFactory.setFeature("http://xml.org/sax/features/namespaces", false);
> aFactory.setFeature("http://apache.org/xml/features/validation/schema
> ", false);
> aFactory.setIgnoringComments(true);
> builder = aFactory.newDocumentBuilder();
> doc = builder.parse(xmlDataFile);
>
>
>
> This is the trace:
>
> at
> com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex
> (DeferredDocumentImpl.java:1944)
> at
> com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild
> (DeferredDocumentImpl.java:644)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters
> (AbstractDOMParser.java:1191)
> at
> com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters
> (XMLDTDValidator.java:862)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
> (XMLDocumentFragmentScannerImpl.java:463)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
> (XML11Configuration.java:807)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
> (XML11Configuration.java:737)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
> (XMLParser.java:107)
> at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse
> (DOMParser.java:225)
> at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse
> (DocumentBuilderImpl.java:283)
> at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
> at XMLParser.Parse(XMLParser.java:89)
> at Main.main(Main.java:116)
>
>
>
> 89 line number points to -> doc = builder.parse(xmlDataFile);

nagineni | 4 Dec 06:25 2009
Picon

Special characters problem while writing XML files using JAXP DOM Parser


Hi,

I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
          <name>naga</name>
          <expr>for(int i=0;i&lt20;i++)</expr>
</template>

I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.

Regards,
Naga.

-----
Regards,
Naga.
--

-- 
View this message in context: http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
Mukul Gandhi | 4 Dec 06:40 2009
Picon

Re: Special characters problem while writing XML files using JAXP DOM Parser

it seems, you are not writing the built in entity reference for
character, "<" appropriately.
you are not writing a semicolon, after &lt.

The parsing of the document you have posted, would likely fail with
this particular error.

The Xerces-J sax.Counter sample gives following error, while parsing
the XML document you have posted:

[Fatal Error] test.xml:4:35: The entity "lt20" was referenced, but not declared.

On Fri, Dec 4, 2009 at 10:55 AM, nagineni <naganirangen_r <at> yahoo.com> wrote:
>
> Hi,
>
> I'm creating xml file using JAXP DOM parser.While writing text data to a
> node parser is writing special characters.Below is the example.
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <template>
>          <name>naga</name>
>          <expr>for(int i=0;i&lt20;i++)</expr>
> </template>
>
> I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
> there any solution around it ?
> Can any one suggest me the solution for this problem ?Thanks in advance.
>
> Regards,
> Naga.

--

-- 
Regards,
Mukul Gandhi
Benson Margulies | 4 Dec 13:13 2009
Picon

Re: Special characters problem while writing XML files using JAXP DOM Parser

If you need a less than, you need to put it all in a CDATA.

On Fri, Dec 4, 2009 at 12:25 AM, nagineni <naganirangen_r <at> yahoo.com> wrote:
>
> Hi,
>
> I'm creating xml file using JAXP DOM parser.While writing text data to a
> node parser is writing special characters.Below is the example.
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <template>
>          <name>naga</name>
>          <expr>for(int i=0;i&lt20;i++)</expr>
> </template>
>
> I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
> there any solution around it ?
> Can any one suggest me the solution for this problem ?Thanks in advance.
>
> Regards,
> Naga.
>
>
> -----
> Regards,
> Naga.
> --
> View this message in context: http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> For additional commands, e-mail: j-users-help <at> xerces.apache.org
>
>
sri kumar | 4 Dec 13:18 2009
Picon

External entity in XML causing null pointer exception during DocumentBuilder.parse

I was trying to parse a XML Document using DOM Parser. 

I got null pointer exception while executing doc = builder.parse(xmlDataFile); 

There were few entities in the XML data file. On removing a particular entity, i was able to parse the file successfully 

The entity was some thing like this 

<!ENTITY SAMPLE.TIF SYSTEM "SAMPLE.TIF" NDATA TIF> 

What could be the reason? 

EDIT: 

Here is the code: 

        DocumentBuilderFactory aFactory = DocumentBuilderFactory.newInstance(); 
        aFactory.setValidating(false); 
        aFactory.setFeature("http://xml.org/sax/features/namespaces", false); 
        aFactory.setFeature("http://apache.org/xml/features/validation/schema", false); 
        aFactory.setIgnoringComments(true); 
        builder = aFactory.newDocumentBuilder(); 
        doc = builder.parse(xmlDataFile); 
This is the trace: 

 at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944) 
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191) 
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107) 
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225) 
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283) 
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180) 
    at XMLParser.Parse(XMLParser.java:89) 
    at Main.main(Main.java:116) 


89 line number points to -> doc = builder.parse(xmlDataFile);


i was able to find the workaround  if i add this code


the issue is resolved. But i need to know the cause of this problem. Was the entity the cause?

Thanks
Sri kumar

The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
Michael Glavassevich | 4 Dec 13:46 2009
Picon

Re: External entity in XML causing null pointer exception during DocumentBuilder.parse

I already responded to you. See [1].

[1] http://markmail.org/message/2qzf4yeeg5iy5o7e.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org

sri kumar <sri_kumar_4u <at> yahoo.co.in> wrote on 12/04/2009 07:18:28 AM:

> I was trying to parse a XML Document using DOM Parser.
>
> I got null pointer exception while executing doc = builder.parse
> (xmlDataFile);
>
> There were few entities in the XML data file. On removing a
> particular entity, i was able to parse the file successfully
>
> The entity was some thing like this
>
> <!ENTITY SAMPLE.TIF SYSTEM "SAMPLE.TIF" NDATA TIF>
>
> What could be the reason?
>
> EDIT:
>
> Here is the code:
>
>         DocumentBuilderFactory aFactory =
> DocumentBuilderFactory.newInstance();
>         aFactory.setValidating(false);
>         aFactory.setFeature("http://xml.org/sax/features/namespaces", false);
>         aFactory.setFeature("http://apache.org/xml/features/validation/schema
> ", false);
>         aFactory.setIgnoringComments(true);
>         builder = aFactory.newDocumentBuilder();
>         doc = builder.parse(xmlDataFile);
> This is the trace:
>
>  at
> com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex
> (DeferredDocumentImpl.java:1944)
>     at
> com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild
> (DeferredDocumentImpl.java:644)
>     at
> com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters
> (AbstractDOMParser.java:1191)
>     at
> com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters
> (XMLDTDValidator.java:862)
>     at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
> (XMLDocumentFragmentScannerImpl.java:463)
>     at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
> (XML11Configuration.java:807)
>     at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
> (XML11Configuration.java:737)
>     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
> (XMLParser.java:107)
>     at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse
> (DOMParser.java:225)
>     at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse
> (DocumentBuilderImpl.java:283)
>     at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
>     at XMLParser.Parse(XMLParser.java:89)
>     at Main.main(Main.java:116)
>
>
> 89 line number points to -> doc = builder.parse(xmlDataFile);
>
> i was able to find the workaround  if i add this code
>
>  aFactory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion
> ", false);
>
> the issue is resolved. But i need to know the cause of this problem.
> Was the entity the cause?
>
> Thanks
> Sri kumar

Michael Glavassevich | 4 Dec 14:23 2009
Picon

Re: Special characters problem while writing XML files using JAXP DOM Parser

Sure, lexically but CDATA is just syntactic sugar. An entity reference (&lt;) or character reference (&#60; or &#x3C;) would also work fine.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org

Benson Margulies <bimargulies <at> gmail.com> wrote on 12/04/2009 07:13:06 AM:

> If you need a less than, you need to put it all in a CDATA.
>
>
> On Fri, Dec 4, 2009 at 12:25 AM, nagineni <naganirangen_r <at> yahoo.com> wrote:
> >
> > Hi,
> >
> > I'm creating xml file using JAXP DOM parser.While writing text data to a
> > node parser is writing special characters.Below is the example.
> >
> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > <template>
> >          <name>naga</name>
> >          <expr>for(int i=0;i&lt20;i++)</expr>
> > </template>
> >
> > I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
> > there any solution around it ?
> > Can any one suggest me the solution for this problem ?Thanks in advance.
> >
> > Regards,
> > Naga.
> >
> >
> > -----
> > Regards,
> > Naga.
> > --
> > View this message in context: http://old.nabble.com/Special-
> characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-
> tp26635769p26635769.html
> > Sent from the Xerces - J - Users mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> > For additional commands, e-mail: j-users-help <at> xerces.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> For additional commands, e-mail: j-users-help <at> xerces.apache.org

keshlam | 4 Dec 14:29 2009
Picon

Re: Special characters problem while writing XML files using JAXP DOM Parser

Or, better, escape the individual troublesome character by expressing it as  &lt;

XML also considers > and & to be reserved characters; they should be expressed as &gt; and &amp;.

<[[CDATA[]]> sections, which provide a block-escaping mechanism, are sometimes useful for hand-generated XML; less so for machine-generated. I generally discourage their use.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
 -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html)


Benson Margulies <bimargulies <at> gmail.com>

12/04/2009 07:13 AM

Please respond to
j-users <at> xerces.apache.org

To
j-users <at> xerces.apache.org
cc
Subject
Re: Special characters problem while writing XML files using JAXP DOM         Parser





If you need a less than, you need to put it all in a CDATA.


On Fri, Dec 4, 2009 at 12:25 AM, nagineni <naganirangen_r <at> yahoo.com> wrote:
>
> Hi,
>
> I'm creating xml file using JAXP DOM parser.While writing text data to a
> node parser is writing special characters.Below is the example.
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <template>
>          <name>naga</name>
>          <expr>for(int i=0;i&lt20;i++)</expr>
> </template>
>
> I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
> there any solution around it ?
> Can any one suggest me the solution for this problem ?Thanks in advance.
>
> Regards,
> Naga.
>
>
> -----
> Regards,
> Naga.
> --
> View this message in context: http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> For additional commands, e-mail: j-users-help <at> xerces.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
For additional commands, e-mail: j-users-help <at> xerces.apache.org


Benson Margulies | 4 Dec 16:53 2009
Picon

Re: Special characters problem while writing XML files using JAXP DOM Parser

I (mis?)understood the original poster to have a strong opinion on the
lexical surface form of the XML.

On Fri, Dec 4, 2009 at 8:23 AM, Michael Glavassevich
<mrglavas <at> ca.ibm.com> wrote:
> Sure, lexically but CDATA is just syntactic sugar. An entity reference
> (&lt;) or character reference (&#60; or &#x3C;) would also work fine.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas <at> ca.ibm.com
> E-mail: mrglavas <at> apache.org
>
> Benson Margulies <bimargulies <at> gmail.com> wrote on 12/04/2009 07:13:06 AM:
>
>> If you need a less than, you need to put it all in a CDATA.
>>
>>
>> On Fri, Dec 4, 2009 at 12:25 AM, nagineni <naganirangen_r <at> yahoo.com>
>> wrote:
>> >
>> > Hi,
>> >
>> > I'm creating xml file using JAXP DOM parser.While writing text data to a
>> > node parser is writing special characters.Below is the example.
>> >
>> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
>> > <template>
>> >          <name>naga</name>
>> >          <expr>for(int i=0;i&lt20;i++)</expr>
>> > </template>
>> >
>> > I want to my XML file output for(int i=0;i<20;i++) inside <expr>
>> > element.Is
>> > there any solution around it ?
>> > Can any one suggest me the solution for this problem ?Thanks in advance.
>> >
>> > Regards,
>> > Naga.
>> >
>> >
>> > -----
>> > Regards,
>> > Naga.
>> > --
>> > View this message in context: http://old.nabble.com/Special-
>> characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-
>> tp26635769p26635769.html
>> > Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
>> > For additional commands, e-mail: j-users-help <at> xerces.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
>> For additional commands, e-mail: j-users-help <at> xerces.apache.org
>
Vincent Herrmann | 13 Dec 15:09 2009
Picon

Get attribute's ref from XSElementDeclaration

Hello,

 

I’m a French developer working on an eclipse plug-in. I’m trying to create an editor which help user to create a XML file.

To help user to create XML file my editor use the Content Assist from eclipse. Completion proposal are given by a XSD file (or other).

 

I’m using xerces to parse this XSD file. I have a problem when I try to get attribute from a XSElementDeclaration.

 

I’m using this code:

 

Private void attributes(XSElementDeclaration element){

                XSTypeDefinition type = element.getTypeDefinition();

XSObjectList attrs = ((XSComplexTypeDefinition)type).getAttributeUses();

For(int i = 0; I < attrs.getLength(); i++){

                XSAttributeUse attrUse = (XSAttributeUse)attrs.item(i);

XSAttributeDeclaration attr = attrUse.getAttrDeclaration() ;

 

System.out.println(attr.getName) ;

}

}

 

This code works but not exactly like I want. He prints:

Lang

Herf

Label

Tittle

 

I want print this :

 

Ns3:Lang

Ns3:herf

Ns3:label

Ns3 :tittle

 

My XML Schema is like this :

 

<xs:attributeGroup name="att.xlink.attribute.label">

    <xs:attribute ref="ns3:label"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.href">

    <xs:attribute ref="ns3:href"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.type">

    <xs:attribute ref="ns3:type"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.title">

    <xs:attribute ref="ns3:title"/>

  </xs:attributeGroup>

 

And in file ns3.xsd :

 

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/1999/xlink" xmlns:ns1="http://www.w3.org/ns/smil" xmlns:mlif="http://www.iso.org/ns/MLIF" xmlns:ns2="http://www.tei-c.org/ns/1.0" xmlns:ns3="http://www.w3.org/1999/xlink">

  <xs:import namespace="http://www.iso.org/ns/MLIF" schemaLocation="MLIF.xsd"/>

  <xs:import namespace="http://www.tei-c.org/ns/1.0" schemaLocation="ns2.xsd"/>

  <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>

  <xs:import namespace="http://www.w3.org/ns/smil" schemaLocation="ns1.xsd"/>

  <xs:attribute name="label"/>

  <xs:attribute name="href"/>

  <xs:attribute name="type"/>

  <xs:attribute name="title"/>

  <xs:attribute name="from"/>

  <xs:attribute name="to"/>

</xs:schema>

 

My code print attribute’s name but I want attribute’s ref. How must I do to get it? I tried but I didn’t find.

Sorry for my poor English :/

 

Regards,

Vincent.

 

 

 

 


Gmane