You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Caroline Wood <Ca...@cpp.co.uk> on 2005/07/18 12:46:27 UTC
Parsing xml
Hi,
I'm new to this so forgive me if this is a daft question...
There is a test schema, very basic, it just contains two fields test1 and
test2.
There is a String of xml:
---
<?xml version = "1.0" encoding = "UTF-8"?><Test
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Test"
test2="test 2" test1="test 1"></Test>
---
I want to unmarshall this to the relevant xmlbean.
---
testDocument = TestDocument.Factory.parse( xml );
---
However the code does not get past the above line, but no error is thrown.
Any ideas what is going wrong?
Thanks!
This is an email from the CPP Group Plc, Holgate Park, York, YO26 4GA; telephone 01904 544500.
This message may contain information that is confidential. If you are not the intended recipient,
you may not peruse, use, disseminate, distribute or copy this message. If you have received this
message in error, please notify the sender immediately by email, facsimile or telephone and either
return or destroy the original message.
The CPP Group Plc accepts no responsibility for any changes made to this message after it has been
sent by the original author. This email has been scanned for all viruses by the MessageLabs Email Security System.
Re: Parsing xml
Posted by Arek Stryjski <ar...@gmail.com>.
>
> There is a test schema, very basic, it just contains two fields test1 and
> test2.
>
> There is a String of xml:
>
> ---
>
> <?xml version = "1.0" encoding = "UTF-8"?><Test
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="Test" test2="test 2" test1="test 1"></Test>
>
> ---
>
> I want to unmarshall this to the relevant xmlbean.
>
> However the code does not get past the above line, but no error is thrown.
>
> Any ideas what is going wrong?
>
I may be wrong but most probably your XML was not recognized by
XMLBeans as TestDocument type. You are not declaring namspace in XML,
and I think in XMLBeans you must do it in Schema and XML with same
URL.
If you can access your data with Cursor but not with getXxx() methods
this is mostly the case.
Did you try to parse somting more simple like:
<test xmlns="http://www.company.com/your.namspace" test2="test 2"
test1="test 1"/>
I'm also not sure if it is right to use <Test> not <test>, but maybe it is?
Hope it will help
Arek
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Parsing xml
Posted by Ulf Ullby <ul...@kb.dk>.
Hi Carolin,
I'm new here too, but I'll tell you what little I know (this is for
XMLBeans 2.0.0). I allways use the Doc.Factory.parse method with a
XML-file (see example below) but I guess it should work the same with a
XML object or stream.
... some imports ...
public class xpathtester {
private static String pathToAltoFile = "ALTO/ALTO00001.xml";
public xpathtester() {
}
public static void main(String[] args) {
xpathtester myXpathtester = new xpathtester();
try {
AltoDocument myAltoDoc = AltoDocument.Factory.parse(new
File(pathToAltoFile));
AltoDocument.Alto myAlto = myAltoDoc.getAlto();
String myXmlPath = "$this//TextLine[@ID='P1_TL00006']";
System.out.println(myAltoDoc.selectPath(myXmlPath)[0].xmlText());
} catch (Exception e) {
}
}
}
Just saw Areks name-space post, but I'll post anyway - it might help.
Best regards,
:) Ulf
Caroline Wood <Ca...@cpp.co.uk>
18-07-2005 12:46
Please respond to
user@xmlbeans.apache.org
To
"'user@xmlbeans.apache.org'" <us...@xmlbeans.apache.org>
cc
Subject
Parsing xml
Hi,
I'm new to this so forgive me if this is a daft question...
There is a test schema, very basic, it just contains two fields test1 and
test2.
There is a String of xml:
---
<?xml version = "1.0" encoding = "UTF-8"?><Test xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:type="Test" test2="test 2"
test1="test 1"></Test>
---
I want to unmarshall this to the relevant xmlbean.
---
testDocument = TestDocument.Factory.parse( xml );
---
However the code does not get past the above line, but no error is thrown.
Any ideas what is going wrong?
Thanks!
This is an email from the CPP Group Plc, Holgate Park, York, YO26 4GA;
telephone 01904 544500.
This message may contain information that is confidential. If you are not
the intended recipient,
you may not peruse, use, disseminate, distribute or copy this message. If
you have received this
message in error, please notify the sender immediately by email, facsimile
or telephone and either
return or destroy the original message.
The CPP Group Plc accepts no responsibility for any changes made to this
message after it has been
sent by the original author. This email has been scanned for all viruses
by the MessageLabs Email Security System.