MCPcopy Create free account
hub / github.com/antchfx/xmlquery / TestOutputXMLWithSpaceDirect

Function TestOutputXMLWithSpaceDirect

node_test.go:634–656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

632}
633
634func TestOutputXMLWithSpaceDirect(t *testing.T) {
635 s := `<?xml version="1.0" encoding="utf-8"?>
636 <class_list>
637 <student>
638 <name xml:space="preserve"> Robert </name>
639 <grade>A+</grade>
640 </student>
641 </class_list>`
642 doc, _ := Parse(strings.NewReader(s))
643 t.Log(doc.OutputXML(true))
644
645 n := FindOne(doc, "/class_list/student/name")
646 expected := `<name xml:space="preserve"> Robert </name>`
647 if g := doc.OutputXML(false); !strings.Contains(g, expected) {
648 t.Errorf(`expected "%s", obtained "%s"`, expected, g)
649 }
650
651 output := html.UnescapeString(doc.OutputXMLWithOptions(WithOutputSelf(), WithoutPreserveSpace()))
652 if strings.Contains(output, "\n") {
653 t.Errorf("the outputted xml contains newlines")
654 }
655 t.Log(n.OutputXML(false))
656}
657
658func TestOutputXMLWithSpaceOverwrittenToPreserve(t *testing.T) {
659 s := `<?xml version="1.0" encoding="utf-8"?>

Callers

nothing calls this directly

Calls 6

ParseFunction · 0.85
FindOneFunction · 0.85
WithOutputSelfFunction · 0.85
WithoutPreserveSpaceFunction · 0.85
OutputXMLMethod · 0.80
OutputXMLWithOptionsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…