Reputation: 479
Here's part of my XML:
<TextLine Version="2" objectID="3" persistentID="6">
<BaseProperties Version="5">
<txBase>665.249</txBase>
<XPos>221.205</XPos>
<angle>0</angle>
<verticalText>false</verticalText>
<objectLeading>0</objectLeading>
</BaseProperties>
<EnclosingObjectType>block</EnclosingObjectType>
<Alignment>center</Alignment>
<TRString>xfsadxzcsdf</TRString>
<RunLengthEncodedCharacterAttributes>
<CharacterAttributes RunCount="13" StyleRef="4098" TextRef="4096" TXKerning="0" TXPostKerning="0" BaselineShifting="0" />
</RunLengthEncodedCharacterAttributes>
<tagName></tagName>
</TextLine>
And for example I put it in xmlString
, in Safari:
var parser = new DOMParser();
var xmlObject = parser.parseFromString(xmlString, 'text/xml');
console.log(xmlObject.getElementsByTagName('TRString')[0].innerHTML);
It return error: TypeError: undefined is not an object
The I tried:
console.log(xmlObject.getElementsByTagName('TRString')[0]);
It give you not #element
but string
. In this example it should be:
<TRString>xfsadxzcsdf</TRString>
I don't have this problem in Chrome. I know it's not hard to solve. But I want to know who is more standard?
Upvotes: 1
Views: 201
Reputation: 61230
does textContent
in Safari work for you?
if so, you can use textContent
, when innerHTML
isn't available...
var xmlValue = xmlObject.getElementsByTagName('TRString')[0].innerHTML ||
xmlObject.getElementsByTagName('TRString')[0].textContent;
Upvotes: 1