Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
saravanaboopati
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

How to solve XML issues?

I am using Xml File like Below

 

 

<store>

<Order>

<Item>Cake</Item>

<Qty>4</Qty>

<Amount>5$</Amount>

<Order ListNo>1</Order ListNo>

</Order>

</store>

 

I have an error DOM Exception while inserting data into the xml file. How to solve the Special character problem while inserting data in to the xml file and also how to solve the White Space between Order ListNo Tag

I use Write() method to insert data into the xml file 

 

<store>

<Order>

<Item>Cake</Item>

<Qty>4</Qty>

<Amount>5</Amount>

<OrderListNo>1</OrderListNo>

</Order>

</store>

 

while the modification in this code is working insertion into the xml file.

 

How to insert special charater $,/,+,!,..etc., into the xml file.

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to solve XML issues?

[ the forum editor, not moderator, is complaining about my html, caveat reader I have no idea what it is whining about but

you can probably figure it out ] 

This is what conforming xml should look like, note the character classes ( explicit list is in hex, probably not much help

but look at whole thing LOL).

 

http://www.w3.org/TR/REC-xml/

 

The API probably provides encoding/decoding if used properly but I'm not sure. In anycase, you can at least post the calls

you are making and the resulting xml to see if special chars get encoded.

 

I happen to have just written a c++ parser skeleton to see if I could make a code generator work from the raw html

spec. So, I happen to know where most of the syntax specs are by now, LOL, "S" is white space,

 

 

[40]    STag    ::=    '<' Name (S Attribute)* S? '>' [WFC: Unique Att Spec] [41]    Attribute    ::=    Name Eq AttValue [VC: Attribute Value Type]         [WFC: No External Entity References]         [WFC: No < in Attribute Values]
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to solve XML issues?

Special chars (which have special meaning within the XML document) must be encoded using their unicode or HTML entity equivalents.

 

For example, the ampersand '&' would be encoded as "&amp;"

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to solve XML issues?

The SAX parser anyway does that automatically but it isn't specified for names,

so the exception is probably valid.  

$ cat xml_state_info | grep "::="| grep -i "name\|stag" | unix2dos

 

[4]    NameChar    ::=    [157]Letter | [158]Digit | '.' | '-' | '_' | ':' | [159]CombiningChar | [160]Extender
[5]    Name        ::=    ([161]Letter | '_' | ':') ([162]NameChar)*
[6]    Names       ::=    [163]Name (#x20 [164]Name)*
[7]    Nmtoken     ::=    ([165]NameChar)+
[17]    PITarget    ::=    [214]Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
[28]     doctypedecl    ::=    '<!DOCTYPE' [256]S [257]Name ([258]S [259]ExternalID)? [260]S? ('[' [261]intSubset ']' [262]S?)? '>' [263][VC: Root Element Type]
[40]    STag         ::=    '<' [360]Name ([361]S [362]Attribute)* [363]S? '>' [364][WFC: Unique Att Spec]
[41]    Attribute    ::=    [365]Name [366]Eq [367]AttValue                    [368][VC: Attribute Value Type]
[42]    ETag    ::=    '</' [378]Name [379]S? '>'
[44]    EmptyElemTag    ::=    '<' [389]Name ([390]S [391]Attribute)* [392]S? '/>' [393][WFC: Unique Att Spec]
[...]

 

 

Entity and char refs are used to indicate escaped things in values or data,

 $ cat xml_state_info | grep "::="| grep -i "\[41\]\|\[9\]\|\[10\]\|entityref\|charref" | unix2dos > /dev/clipboard

 

 

[9]     EntityValue      ::=    '"' ([^%&"] | [175]PEReference | [176]Reference)* '"'
[10]    AttValue         ::=    '"' ([^<&"] | [179]Reference)* '"'
[41]    Attribute    ::=    [365]Name [366]Eq [367]AttValue                    [368][VC: Attribute Value Type]
[66]    CharRef    ::=    '&#' [0-9]+ ';'
[67]    Reference      ::=    [581]EntityRef | [582]CharRef
[68]    EntityRef      ::=    '&' [583]Name ';'             [584][WFC: Entity Declared]

 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to solve XML issues?

The SAX parser will decode HTML entities, but the SAX parser wil not properly encode these entities in the XML document, The SAX parser did not create the document, right? What am I missing?

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to solve XML issues?

I haven't used the DOM classes ( actually I am doing this right now) but rather commenting that it is reasonable

to expect an XML codec to deal with &; in both forward and reverse directions and I can testify to the fact that

the SAX parser seemed to do this. There is no legal way to take something you present to the API

that is supposed to be syntactically a Name and have it do anything to make valid XML. 

The syntax diagram doesn't allow for escape sequences in the name, so it is moot.

I don't see how something that starts <foo&#x20;bar would be valid if that is what you thought it should do.

CharRef is not part of Name,  

$ cat xml_full_file |  grep -i -A 3 "CharRef"
[66]    CharRef    ::=    '&#' [0-9]+ ';'
                          | '&#x' [0-9a-fA-F]+ ';' [579][WFC: Legal Character]
 

 

 Further, the

excluded characters from values and data dont' all, if any, include "$" which IIRC was the char used to illustrate

the problem.

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to solve XML issues?

Perhaps the original poster would like to show us a code snippet showing actual classes/methods used and describe the actual exception and the line of code throwing the exception.

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to solve XML issues?

Well, at this point I would conclude that there is no mystery as the "$" probably belongs there as it

doesn't AFAIK have to be escaped based on [^<&] class and the space in the name is not salvagable

so the exception makes sense if API needs a name. If you want a tag that contains an attribute there is

probably a different call to make which is obvious from the docs once you know the DOM terms.