Creating XdmNode from String

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Creating XdmNode from String

Julia.Nissen

Hello,

 

what is the best way to create a XdmNode for a text-node from a String?

(I need this to set the initial context node for a XsltTransformer)

 

Regards,

Julia Nissen


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel:
Fax:
E-Mail: [hidden email]


GDV Dienstleistungs-GmbH
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRB 145291
USt.-IdNr : DE 205183123

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Fred di Giuseppe Chiachiarella
Thomas Fischer

Aufsichtsratsvorsitzender: Werner Schmidt

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating XdmNode from String

Michael Kay
I think the cleanest way to do it (because it only uses stable APIs) is probably

XQueryCompiler q = processor.newXQueryCompiler();
XQueryEvaluator e = q.compile("declare variable $s external; text{$s}").load();
e.setExternalVariable(new QName("s"), new XdmAtomicValue("This is the string"));
XdmNode textNode = (XdmNode)e.evaluateSingle();

If you're happy to dive into Saxon classes that could change over time, you could do:

Orphan node = new Orphan(processor.getUnderlyingConfiguration();
node.setNodeKind(Type.TEXT);
node.setStringValue("This is the string");
XdmNode textNode = new XdmNode(node);


Michael Kay
Saxonica




On 19 Jul 2017, at 10:10, Julia Nissen <[hidden email]> wrote:

Hello,

 

what is the best way to create a XdmNode for a text-node from a String?

(I need this to set the initial context node for a XsltTransformer)

 

Regards,

Julia Nissen


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel:
Fax:
E-Mail: [hidden email]



GDV Dienstleistungs-GmbH
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRB 145291
USt.-IdNr : DE 205183123

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Fred di Giuseppe Chiachiarella
Thomas Fischer

Aufsichtsratsvorsitzender: Werner Schmidt

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating XdmNode from String

Julia.Nissen

I use your second solution and it works fine for me. Thank you!

 

Regards,

Julia Nissen

 


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel:
Fax:
E-Mail: [hidden email]


Von: Michael Kay [mailto:[hidden email]]
Gesendet: Mittwoch, 19. Juli 2017 12:24
An: Mailing list for the SAXON XSLT and XQuery processor <[hidden email]>
Betreff: Re: [saxon] Creating XdmNode from String

 

I think the cleanest way to do it (because it only uses stable APIs) is probably

 

XQueryCompiler q = processor.newXQueryCompiler();

XQueryEvaluator e = q.compile("declare variable $s external; text{$s}").load();

e.setExternalVariable(new QName("s"), new XdmAtomicValue("This is the string"));

XdmNode textNode = (XdmNode)e.evaluateSingle();

 

If you're happy to dive into Saxon classes that could change over time, you could do:

 

Orphan node = new Orphan(processor.getUnderlyingConfiguration();

node.setNodeKind(Type.TEXT);

node.setStringValue("This is the string");

XdmNode textNode = new XdmNode(node);

 

 

Michael Kay

Saxonica

 

 

 

 

On 19 Jul 2017, at 10:10, Julia Nissen <[hidden email]> wrote:

 

Hello,

 

what is the best way to create a XdmNode for a text-node from a String?

(I need this to set the initial context node for a XsltTransformer)

 

Regards,

Julia Nissen


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel:
Fax:
E-Mail: [hidden email]

 

GDV Dienstleistungs-GmbH
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRB 145291
USt.-IdNr : DE 205183123

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Fred di Giuseppe Chiachiarella
Thomas Fischer

Aufsichtsratsvorsitzender: Werner Schmidt

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites,
Slashdot.org! http://sdm.link/slashdot_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help

 

GDV Dienstleistungs-GmbH
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRB 145291
USt.-IdNr : DE 205183123

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Fred di Giuseppe Chiachiarella
Thomas Fischer

Aufsichtsratsvorsitzender: Werner Schmidt

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...